IP地址显示

1
2
3
4
5
6
7
In [2]: url = "https://ifconfig.me/ip"
In [4]: requests.get(url).text
Out[4]: '112.96.242.221'

In [5]: url = "https://myip.ipip.net/"
In [6]: requests.get(url).text
Out[7]: '当前 IP:112.96.242.221 来自于:中国 广东 广州 联通\n'

读取 jsonline文件

1
2
3
4
5
6
7
8
9
10
"""
大概长这样
{}
{}
{}
"""

with open("spus.jsonl", encoding="utf8") as fp:
for item in jsonlines.Reader(fp):
print(item)

openpyxl

读取表格

1
2
3
4
5
6
7
workbook = load_workbook(file_path)
sheet = workbook.active # 获取当前工作簿的活动工作表
for row in sheet.iter_rows(
values_only=True, # 只返回每行的值
min_row=2 # 从第二行开始读,跳过标题
):
data.append(row)

写入表格

1
2
3
4
5
workbook = Workbook()
sheet = workbook.active
for row in data:
sheet.append(row)
workbook.save("cxs.xlsx")

zipfile

解压缩

1
2
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(file_path)

pytesseract ocr

图像文字识别

exe下载:https://github.com/UB-Mannheim/tesseract/wiki

1
2
pytesseract.pytesseract.tesseract_cmd = "D:\\tessert_ocr\\tesseract.exe"
print(pytesseract.image_to_string(Image.open("cxs.png")))

moviepy

提取视频音频

1
2
3
4
5
6
7
8
9
10
11
from moviepy.editor import *

def split_audio(mkv_file_path, mp3_file_path):
video = VideoFileClip(mkv_file_path)
audio = video.audio
audio.write_audiofile(mp3_file_path)

# 示例用法
mkv_file_path = "Survivorman.S01E06.720p.HDTV.AC3.x264-NTb.mkv"
mp3_file_path = "06.mp3"
split_audio(mkv_file_path, mp3_file_path)

supervisor

参考:https://mp.weixin.qq.com/s/zqSyqCD-e3SeLc0tvFRk8A

用于部署持久化进程