mirror of
https://github.com/LibraHp/GetQzonehistory.git
synced 2024-12-27 22:49:09 +00:00
优化代码,去除非法字符/Emoji表情
This commit is contained in:
parent
3f96e387c7
commit
3e331172c3
38
main.py
38
main.py
@ -24,6 +24,7 @@ user_message = list()
|
|||||||
leave_message = list()
|
leave_message = list()
|
||||||
forward_message = list()
|
forward_message = list()
|
||||||
|
|
||||||
|
|
||||||
# 信号处理函数
|
# 信号处理函数
|
||||||
def signal_handler(signal, frame):
|
def signal_handler(signal, frame):
|
||||||
# 在手动结束程序时保存已有的数据
|
# 在手动结束程序时保存已有的数据
|
||||||
@ -135,23 +136,24 @@ def save_data():
|
|||||||
# 可见说说中可能存在多张图片
|
# 可见说说中可能存在多张图片
|
||||||
item_pic_links = str(item[2]).split(",")
|
item_pic_links = str(item[2]).split(",")
|
||||||
for item_pic_link in item_pic_links:
|
for item_pic_link in item_pic_links:
|
||||||
if item_pic_link is not None and len(item_pic_link) > 0 and 'http' in item_pic_link:
|
# 如果图片链接为空或者不是http链接,则跳过
|
||||||
# 保存图片
|
if not item_pic_link or len(item_pic_link) == 0 or 'http' not in item_pic_link:
|
||||||
pic_name = re.sub(r'[\\/:*?"<>|]', '_', item_text) + '.jpg'
|
continue
|
||||||
# 去除文件名中的空格
|
# 去除非法字符 / Emoji表情
|
||||||
pic_name = pic_name.replace(' ', '')
|
pic_name = re.sub(r'\[em\].*?\[/em\]|[^\w\s]|[\\/:*?"<>|\r\n]+', '_', item_text).replace(" ", "") + '.jpg'
|
||||||
|
# 去除文件名中的空格
|
||||||
# 限制文件名长度
|
pic_name = pic_name.replace(' ', '')
|
||||||
if len(pic_name) > 40:
|
# 限制文件名长度
|
||||||
pic_name = pic_name[:40] + '.jpg'
|
if len(pic_name) > 40:
|
||||||
# pic_name = pic_name.split(':')[1] + '.jpg'
|
pic_name = pic_name[:40] + '.jpg'
|
||||||
response = requests.get(item_pic_link)
|
# pic_name = pic_name.split(':')[1] + '.jpg'
|
||||||
if response.status_code == 200:
|
response = requests.get(item_pic_link)
|
||||||
# 防止图片重名
|
if response.status_code == 200:
|
||||||
if os.path.exists(pic_save_path + pic_name):
|
# 防止图片重名
|
||||||
pic_name = pic_name.split('.')[0] + "_" + str(int(time.time())) + '.jpg'
|
if os.path.exists(pic_save_path + pic_name):
|
||||||
with open(pic_save_path + pic_name, 'wb') as f:
|
pic_name = pic_name.split('.')[0] + "_" + str(int(time.time())) + '.jpg'
|
||||||
f.write(response.content)
|
with open(pic_save_path + pic_name, 'wb') as f:
|
||||||
|
f.write(response.content)
|
||||||
if user_nickname in item_text:
|
if user_nickname in item_text:
|
||||||
if '留言' in item_text:
|
if '留言' in item_text:
|
||||||
leave_message.append(item[:-1])
|
leave_message.append(item[:-1])
|
||||||
@ -262,7 +264,7 @@ if __name__ == '__main__':
|
|||||||
texts.append([put_time, text, img])
|
texts.append([put_time, text, img])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"获取QQ空间互动消息发生异常: {str(e)}")
|
print(f"获取QQ空间互动消息发生异常: {str(e)}")
|
||||||
texts = [t + [""] for t in texts] # 确保texts是四列, 防止后续保存结果出现问题
|
texts = [t + [""] for t in texts] # 确保texts是四列, 防止后续保存结果出现问题
|
||||||
try:
|
try:
|
||||||
user_moments = GetAllMoments.get_visible_moments_list()
|
user_moments = GetAllMoments.get_visible_moments_list()
|
||||||
if user_moments and len(user_moments) > 0:
|
if user_moments and len(user_moments) > 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user