用 pymupdf 将电子发票转成图片,再插入报销单中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# %%
import os
import fitz
from pprint import pprint

fapiao_dir = 'src/'

zhantiedan = 'zhantiedan_blank.pdf'
ztd_pdf = fitz.open(zhantiedan)

new_name = 'fapiao_dayin.pdf'
new_pdf = fitz.open()


def fapiao_zhantie(fapiao=''):

print(f'\n=== fapiao pdf file:\n {fapiao}')
src_pdf = fitz.open(fapiao)

for p, page in enumerate(src_pdf):
pixmap = page.get_pixmap(dpi=300)
pixmap.save(f'{fapiao}_{str(p)}.png')

new_pdf.insert_pdf(ztd_pdf)
end_page = new_pdf[-1]
end_page.insert_image((100, 100, 700, 500), pixmap=pixmap)

src_pdf.close()

new_pdf.save(new_name)
print(f' {fapiao} :\n*** Done! ***\n')


for dir, folders, files in os.walk(fapiao_dir):
for file in files:
path = os.path.join(dir, file)
print(path)
if path[-4:] == '.pdf':
fapiao_zhantie(path)

ztd_pdf.close()
new_pdf.close()


ffmpeg 使用说明

查看使用说明:ffmpeg -h

1
2
3
4
5
6
7
8
9
# usage: 
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

# options:
-ab: 比特率
-vn: video no
-map_metadata 0: 保留 meta data

-y: overwrite output files
阅读全文 »

群晖自带的 ffmpeg 版本较低、支持编码库也比较少, 似乎不支持h265。从 SynoCommunity 升级 ffmpeg。

SynoCommunity 上给出了 DSM7版本 各套件的适配情况:

issue #4524: https://github.com/SynoCommunity/spksrc/issues/4524

1. 先从 SynoCommunity 安装 ffmpeg 套件

2. 设置 Video Station 调用 SynoCommunity 版本的 ffmpeg

https://github.com/SynoCommunity/spksrc/wiki/FAQ-FFmpeg

命令如下:

1
2
3
4
5
6
sudo mv /var/packages/VideoStation/target/bin/ffmpeg /var/packages/VideoStation/target/bin/ffmpeg.old
sudo ln -sf /var/packages/ffmpeg/target/bin/ffmpeg /var/packages/VideoStation/target/bin/ffmpeg
sudo cp -p /var/packages/VideoStation/target/lib/libsynovte.so /var/packages/VideoStation/target/lib/libsynovte.so.old
sudo sed -i 's/eac3/ZXXZ/' /var/packages/VideoStation/target/lib/libsynovte.so
sudo sed -i 's/dts/ZXZ/' /var/packages/VideoStation/target/lib/libsynovte.so
sudo sed -i 's/truehd/ZXZZXZ/' /var/packages/VideoStation/target/lib/libsynovte.so

恢复原来的设置

1
2
3
4
5
# Reverse the above changes:

sudo mv -f /var/packages/VideoStation/target/bin/ffmpeg.old /var/packages/VideoStation/target/bin/ffmpeg
sudo mv -f /var/packages/VideoStation/target/lib/libsynovte.so.old /var/packages/VideoStation/target/lib/libsynovte.so

阅读全文 »

PDF文档全文翻译,保留原有的PDF格式

1. 采用 pymupdf 识别 pdf 的图片和文字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import fitz
import re
from pprint import pprint

pdf_name = 'xxx-en.pdf'
print(f'Source pdf file: {pdf_name} \n')
src_pdf = fitz.open(pdf_name)
new_pdf = fitz.open()

for p, page in enumerate(src_pdf):
print(f'\n- translating PAGE -{p}- ...')

# 1.1 创建大小相同的新页面
new_page = new_pdf.new_page(width=page.rect.width, height=page.rect.height)

blocks = page.get_text('dict')['blocks']

# 1.2 图片
img_blks = [b for b in blocks if b['type'] == 1]
for img in img_blks:
# pprint(img)
new_page.insert_image(img['bbox'], stream=img['image'])

# 1.3 文字
txt_blks = [b for b in blocks if b['type'] != 1]
for txt in txt_blks:
text_tmp = ''.join([s['text'] for l in txt['lines'] for s in l['spans']])
text_tmp = re.sub('[@#$%^&*\'\"\n\r\t]', ' ', text_tmp).strip()

if text_tmp:
# print(txt['bbox'], text_tmp)

text_translate = '中国 ' + text_tmp
# text_translate = youdao(text_tmp)
new_page.insert_textbox(txt['bbox'], text_translate,
fontsize=6,
fontname='simhei',
fontfile=r'C:\Windows\Fonts\simhei.ttf')

# if p == 1:
# break

new_name = pdf_name.replace('.pdf', '-zh.pdf')
new_pdf.save(new_name)

print('\n------Done!-------')

阅读全文 »

这里可查CPU、内存型号
https://kb.synology.com/en-us/DSM/tutorial/What_kind_of_CPU_does_my_NAS_have

  • 群晖型号:DS218+
  • CPU :Intel Celeron J3355 Dual Core
  • 架构: Apollolake(x64):
  • 内存:DDR3L SODIMM 2GB

群晖 DS218+ 原装内存只有 2GB,机器内预留了一个内存插槽,准备再加一个。

看了网上说群晖的机子认内存,而且最大识别到8G,也有说16G的,可以命令查询。

查看群晖内存 sudo dmidecode -t memory

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$ sudo dmidecode -t memory
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.0.0 present.

Handle 0x0023, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 16 GB
Error Information Handle: No Error
Number Of Devices: 1

Handle 0x0025, DMI type 17, 40 bytes
Memory Device
Array Handle: 0x0023
Error Information Handle: No Error
Total Width: 8 bits
Data Width: 8 bits
Size: 2048 MB
Form Factor: SODIMM
Set: None
Locator: ChannelB-DIMM0
Bank Locator: BANK 1
Type: DDR3
Type Detail: Synchronous
Speed: 1600 MT/s
Manufacturer: 0824
Serial Number: 25073816
Asset Tag: 9876543210
Part Number: D3SS56161XL10AA
Rank: Unknown
Configured Memory Speed: 1600 MT/s
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: Unknown

可以看到 Maximum Capacity: 16 GB

阅读全文 »

暑假马上结束了,悠悠约了琪琪姐姐要好好玩,连续几天晚上吃过饭都骑自行车去秦淮河边公园,一直玩到9点多。

我准备给她自行车加一个小灯,这样方便我能一眼找到她。

灯就用仙女棒上的,棒子已经丢了,一串小灯还留着,挺长的有1米多,但纽扣电池没电了,换成两节5号电池,刚好有个电池盒。

我正在安,悠悠说,爸爸你要做成能拆下来的。

我问为啥?

我下次要换大自行车,还把这灯安上去。

我说不用,到时候灯也换新的。

过一会,我把灯缠好了,线头准备焊到电池盒上。

悠悠说,你这可以换电池吗?没电了咋办。

可以换的,电池盒子可以打开。

有开关吗?灯是一直亮着的吗?

有。呶,关了。

阅读全文 »

配置 Github Action, 推送企业微信消息

1. 将企业微信的 secret 添加到 Action Secret

打开 hexo-source 仓库设置,在 Secrets 选项中,分别新建 3个 repo secret:

  • 名称设为CORP_ID, 内容为corpid的内容
  • 名称设为CORP_SECRET, 内容为secret的内容
  • 名称设为AGENT_ID, 内容为agentid的内容

2. 修改 wechat-push 代码

以发送 commit log 信息为列, 代码如下:

阅读全文 »

qiye-wechat-push

企业微信推送 python版

  • 不需要安装企业微信客户端
  • 可在微信中直接收到文本消息,内容显全文

1. 企业微信注册

  • 1.1 注册企业

用电脑打开企业微信官网,https://work.weixin.qq.com/, 注册一个企业

  • 1.2 获取企业ID

我的企业 –> 最下边可以看到企业ID: corpid

  • 1.3 获取应用ID

管理企业 –> 应用管理 –> 创建应用

创建完成后可得到应用ID agentid

  • 1.4 获取Secret

还在应用页面, 获取 Secret, 需要在企业微信客户端里接收。

这样就得到了 secret

2. 发送文本消息 python

阅读全文 »

DSM 升级至 7.0 之后,很多第三方套件不兼容了。

SynoCommunity 上给出了各套件的适配情况:

issue #4524: https://github.com/SynoCommunity/spksrc/issues/4524

zsh 也在其中,已经可以 build 了,但是还没正式发布。

我试着自己编译一下。

CPU 架构

我的群晖是DS218+,CPU 是Intel Celeron J3355,架构是 apollolake(x64).

这里可以查:

https://github.com/SynoCommunity/spksrc/wiki/Architecture-per-Synology-model

https://kb.synology.com/en-us/DSM/tutorial/What_kind_of_CPU_does_my_NAS_have

阅读全文 »

一、WSL 安装 Ubuntu20.04

  1. Win10 启用 WSL

管理员身份运行:

1
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

重启电脑。

开启虚拟器特性

1
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

下载安装包:

设置默认版本:

1
wsl --set-default-version 2

ref: https://docs.microsoft.com/en-us/windows/wsl/install-win10

  1. 打开 Microsoft Store,安装 Ubuntu20.04

  2. 启动 Ubuntu20.04,创建账号、密码

  3. 安装 Windows Terminal(可选)

用 scoop 安装。

1
scoop install windows-terminal

windows-terminal 简单设置:

  • 启动目录: //wsl$/Ubuntu-20.04//home/bo
  • 字体: Jetbrains Mono
  1. 设置源,更新(可选)
阅读全文 »

ffmpeg 使用说明

查看使用说明:ffmpeg -h

1
2
3
4
5
6
# usage: 
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

# options:
-ab: -ab bitrate audio bitrate (please use -b:a)
-y: overwrite output files

转换命令如下:

1
ffmpeg -i xxx.flac -ab 320k xxx.mp3 -y'

这次我们用到的主要是 -ab 命令,用来指定音频转换的比特率,常见的有: 192K, 320K 等。

阅读全文 »

视频内字幕提取

这里是针对内封了硬字幕的视频,字幕已经成为了画面的一部分。

思路:简单用 opencv 提取视频内的所有帧,然后用 tesseract 对图片进行 ocr 识别。

目前的效率较低、准确度也一般,凑合用。

0. 首先需要配置一下

0.1 安装 python 库

  • python-opencv
  • pytesseract
  • scikit-image

0.2 安装 tesseract 软件,下载训练好的语言包

  • tesseract 软件可以用 scoop 安装:
1
scoop install tesseract
  • tesseract 训练好的语言包

帮助文档: https://tesseract-ocr.github.io/tessdoc/

官方体提供了三种训练好的模型:

  • tessdata
  • tessdata_best
  • tessdata_fast

我们这里选择 tessdata_fast

阅读全文 »

1. GMiner 说明

ref: https://github.com/develsoftware/GMinerRelease

  • 1.1 下载 gminer_2_XX_windows64.zip, 解压后目录如下:
1
2
3
4
5
6
├───miner.exe            # 主程序
├───mine_aeternity.bat # 快捷脚本
├───...
├───readme.txt # 说明文档
├───sample_config.txt # 配置文件

  • 1.2 参数设置说明

以在 火币矿池以太币 为例,

https://pool.huobi.pe/pow/help/3/all

主要参数如下:

1
2
3
4
--algo:     算法,可省略; 对于以太币,默认 ethash
--server: 矿池地址; 这里填写的是火币矿池
--user: 火币矿池的子账户名;注意不是钱包地址,也不是邮箱号
...
  • 1.3 使用方法( 直接命令行运行 )
1
./miner --algo ethash --server stratum+tcp://es.huobipool.com:1800 --user shenyoyo0706

也可以用配置文件运行, 或用快捷脚本运行, 参数设置方法是一样的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Sample configuration file to mine BitcoinGold
# options has same names as command line arguments
# you can access to environment variables by %variable_name%
# run "miner --config sample_config.txt"

[common]
algo=ethash
templimit=80
color=1
api=10555
logfile=miner.log
log_date=1
log_newjob=0

# Main pool
[server]
host=es.huobipool.com
port=1800
user=shenyoyo0706
pass=x
阅读全文 »

ref: (https://github.com/ScoopInstaller/Scoop)

1. 安装 scoop

1.1 安装 PowerShell 5.0 以上版本

1.2 以当前Win账户运行PowerShell

1
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

1.3 安装 scoop

1
2
irm get.scoop.sh | iex

1
2
3
4
5
6
7
8
cd ~
curl -o scoop_install.ps1 https://ghproxy.net/https://raw.githubusercontent.com/ScoopInstaller/install/master/install.ps1

# 修改 `scoop_install.ps1` 内容:
(Get-Content scoop_install.ps1).replace('https://github.com/ScoopInstaller/', 'https://ghproxy.net/https://github.com/ScoopInstaller/') | Set-Content scoop_install.ps1

# 安装
.\scoop_install.ps1

使用默认安装时经常卡住,是因为 https://get.scoop.sh 其实指向了 https://raw.githubusercontent.com/,因而导致安装失败。

对应的安装文件在这里: https://github.com/ScoopInstaller/Install/blob/master/install.ps1

1.4 可用的镜像源

阅读全文 »

1.安装

以scoop安装oh-my-posh3。

1
scoop install oh-my-posh

2. 配置文件

新建、修改配置文件,运行:

1
2
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
code $PROFILE

加入以下内容:

1
2
3
4
5

chcp 65001
Set-PSReadLineOption -PredictionSource History

oh-my-posh init pwsh --config ~\scoop\persist\oh-my-posh\themes\yo.omp.json | Invoke-Expression

ref: https://ohmyposh.dev/docs/installation

阅读全文 »

caj2pdf:将知网caj文件转换为pdf

https://github.com/caj2pdf/caj2pdf/

使用

1. 环境和依赖(win10)

2. 官方用法

阅读全文 »

一、WSL 安装 Ubuntu18.04

  1. Win10 启用 WSL

管理员身份运行:

1
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

重启电脑。

  1. 打开 Microsoft Store,安装 Ubuntu18.04

  2. 启动 Ubuntu18.04,创建账号、密码

  3. 安装 Windows Terminal(可选)

用 scoop 安装。

1
scoop install windows-terminal

windows-terminal 简单设置:字体、启动目录。

1
2
3
4
5
6
7
8
9
10
{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"fontFace": "Jetbrains Mono",
"fontSize": 11,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu-18.04//home/bo",

}
  1. 设置源,更新(可选)
阅读全文 »

1. 1602a LCD屏

  • 接线端子表:
序号 LCD屏 16PIN 树莓派 40PIN 物理序号 备注
1 VSS 06 GND
2 VDD 02 5V
3 V0 电位器 对比度,0-5V
4 RS 08 GPIO-14
5 RW 06 写模式:接地
6 EN 10 GPIO-15
7 D0 -
8 D1 -
9 D2 -
10 D3 -
11 D4 11 GPIO-17
12 D5 12 GPIO-18
13 D6 13 GPIO-27
14 D7 15 GPIO-22
15 A 串约500Ω电阻后接02 背光正
16 K 06 背光负
阅读全文 »

1. 墨水屏

  • 型号:微雪 2.9inch e-Paper Module, 带驱动板,8PIN

  • 工作电压:3.3V/5V

  • 通信接口:SPI

  • 分辨率:296 x 128

  • 显示颜色:黑、白

  • 局部刷新:0.3s

  • 全局刷新 :2s

  • 接线表:

墨水屏 8PIN 树莓派 40PIN 物理序号 备注
VCC 1 3.3V
GND 6 GND
DIN 19
CLK 23
CS 24
DC 22
RST 11
BUSY 18
阅读全文 »

之前用的小米路由3,小两房勉强够用。

搬到新家之后就明显不给力了。

户型图

新家的户型:

交付时的布线:

房间 网口
弱电箱-客厅前墙(电视) 网线 + 有线电视同轴线
弱电箱-客厅后墙 网线 + 电话线
弱电箱-主卧 网线 + 电话线
弱电箱-次卧 网线 + 电话线
弱电箱-书房 网线 + 电话线
弱电箱-卫生间 电话线
  • 网线和有线电视/电话线都是两根线同走一个穿线管
  • 电话线其实也是8芯网线,只不过接口是电话接口
阅读全文 »