-
Notifications
You must be signed in to change notification settings - Fork 134
/
入库.py
33 lines (28 loc) · 931 Bytes
/
入库.py
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
import pymysql
import re
conn = pymysql.connect(
host='localhost',
user='root',
password='000000',
db='test',
charset='utf8mb4',
port=3306)
cur = conn.cursor()
with open(r"D:\临时文件\wechatLog\txt\你跺你也麻\林瓜瓜.txt", encoding='utf-8') as f:
lines = f.readlines()
filter_lines = []
reg = "^.+[\u4E00-\u9FFF]\s\(.+\):"
for line in lines:
# 去除转发的聊天记录 简单过滤
if (line.startswith('你跺你也麻') or line.startswith('喇叭精')) and re.match(reg, line):
filter_lines.append(line.strip())
for line in filter_lines:
s1 = line.find(" ")
s2 = line.find("):")
name = line[:s1]
time = line[s1 + 2:s2]
content = line[s2 + 2:]
print(line)
insert_sql = f"insert into log(user,datetime,content) values ('{name}','{time}' ,'{pymysql.escape_string(content)}')"
cur.execute(insert_sql)
conn.commit()