mirror of
https://github.com/LibraHp/GetQzonehistory.git
synced 2024-12-27 06:29:55 +00:00
Merge pull request #32 from SwimmingLiu/main
同步分页获取未删除说说代码至主线程, 说说图片替换为高清图, 优化部分代码
This commit is contained in:
commit
a476cf0342
31
main.py
31
main.py
@ -1,3 +1,4 @@
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
import platform
|
||||
import subprocess
|
||||
@ -16,6 +17,12 @@ import requests
|
||||
import time
|
||||
import platform
|
||||
|
||||
texts = list()
|
||||
all_friends = list()
|
||||
other_message = list()
|
||||
user_message = list()
|
||||
leave_message = list()
|
||||
forward_message = list()
|
||||
|
||||
# 信号处理函数
|
||||
def signal_handler(signal, frame):
|
||||
@ -69,6 +76,9 @@ def render_html(shuoshuo_path, zhuanfa_path):
|
||||
image_html = '<div class="image">'
|
||||
for img_url in img_url_lst:
|
||||
if img_url and img_url.startswith('http'):
|
||||
# 将图片替换为高清图
|
||||
img_url = str(img_url).replace("/m&ek=1&kp=1", "/s&ek=1&kp=1")
|
||||
img_url = str(img_url).replace(r"!/m/", "!/s/")
|
||||
image_html += f'<img src="{img_url}" alt="图片">\n'
|
||||
image_html += "</div>"
|
||||
comment_html = ""
|
||||
@ -186,8 +196,18 @@ def open_file(file_path):
|
||||
# macOS 系统使用 subprocess 和 open 命令
|
||||
subprocess.run(['open', file_path])
|
||||
elif platform.system() == 'Linux':
|
||||
# Linux 系统使用 subprocess 和 xdg-open 命令
|
||||
subprocess.run(['xdg-open', file_path])
|
||||
# Linux 系统,首先检查是否存在 xdg-open 工具
|
||||
if shutil.which('xdg-open'):
|
||||
subprocess.run(['xdg-open', file_path])
|
||||
# 如果 xdg-open 不存在,检查是否存在 gnome-open 工具(适用于 GNOME 桌面环境)
|
||||
elif shutil.which('gnome-open'):
|
||||
subprocess.run(['gnome-open', file_path])
|
||||
# 如果 gnome-open 不存在,检查是否存在 kde-open 工具(适用于 KDE 桌面环境)
|
||||
elif shutil.which('kde-open'):
|
||||
subprocess.run(['kde-open', file_path])
|
||||
# 如果以上工具都不存在,提示用户手动打开文件
|
||||
else:
|
||||
print("未找到可用的打开命令,请手动打开文件。")
|
||||
else:
|
||||
print(f"Unsupported OS: {platform.system()}")
|
||||
|
||||
@ -205,12 +225,7 @@ if __name__ == '__main__':
|
||||
except Exception as e:
|
||||
print(f"登录失败:请重新登录,错误信息:{str(e)}")
|
||||
exit(0)
|
||||
texts = []
|
||||
all_friends = []
|
||||
other_message = []
|
||||
user_message = []
|
||||
leave_message = []
|
||||
forward_message = []
|
||||
|
||||
count = Request.get_message_count()
|
||||
try:
|
||||
# 注册信号处理函数
|
||||
|
@ -1,4 +1,5 @@
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@ -11,13 +12,15 @@ from util import RequestUtil as Request
|
||||
from util import LoginUtil
|
||||
from util import ToolsUtil as Tool
|
||||
|
||||
WORKDIR = "./resource/fetch-all/"
|
||||
QQ_NUMBER = Request.uin
|
||||
WORKDIR = f"./resource/fetch-all/{QQ_NUMBER}" # 通过QQ号进行区分配置文件,防止误加载其他用户信息
|
||||
USER_QZONE_INFO = 'user_qzone_info.json'
|
||||
QZONE_MOMENTS_ALL = 'qzone_moments_all.json'
|
||||
|
||||
|
||||
# 获取所有可见的未删除的说说+高清图片(包含2014年之前)
|
||||
def get_visible_moments_list():
|
||||
|
||||
# 1. 获取说说总条数
|
||||
user_qzone_info = Tool.read_txt_file(WORKDIR, USER_QZONE_INFO)
|
||||
if not user_qzone_info:
|
||||
@ -25,15 +28,16 @@ def get_visible_moments_list():
|
||||
qq_userinfo_response = get_user_qzone_info(1)
|
||||
Tool.write_txt_file(WORKDIR, USER_QZONE_INFO, qq_userinfo_response)
|
||||
user_qzone_info = Tool.read_txt_file(WORKDIR, USER_QZONE_INFO)
|
||||
|
||||
if not Tool.is_valid_json(user_qzone_info):
|
||||
print("获取QQ空间信息失败")
|
||||
return None
|
||||
json_dict = json.loads(user_qzone_info)
|
||||
totalMomentsCount = json_dict['total']
|
||||
print(f'你的未删除说说总条数{totalMomentsCount}')
|
||||
total_moments_count = json_dict['total']
|
||||
print(f'你的未删除说说总条数{total_moments_count}')
|
||||
|
||||
# 当前未删除说说总数为0, 直接返回
|
||||
if totalMomentsCount == 0:
|
||||
if total_moments_count == 0:
|
||||
return None
|
||||
|
||||
# 2. 获取所有说说数据
|
||||
@ -41,8 +45,22 @@ def get_visible_moments_list():
|
||||
qzone_moments_all = Tool.read_txt_file(WORKDIR, QZONE_MOMENTS_ALL)
|
||||
if not qzone_moments_all:
|
||||
# 缓存未找到,开始请求获取所有未删除说说
|
||||
qq_userinfo_response = get_user_qzone_info(totalMomentsCount)
|
||||
Tool.write_txt_file(WORKDIR, QZONE_MOMENTS_ALL, qq_userinfo_response)
|
||||
# qq_userinfo_response = get_user_qzone_info(totalMomentsCount)
|
||||
# Tool.write_txt_file(WORKDIR, QZONE_MOMENTS_ALL, qq_userinfo_response)
|
||||
# qzone_moments_all = Tool.read_txt_file(WORKDIR, QZONE_MOMENTS_ALL)
|
||||
default_page_size = 30 # 默认一页30条
|
||||
total_page_num = math.ceil(total_moments_count / default_page_size) # 总页数
|
||||
all_page_data = [] # 用于存储所有页的数据
|
||||
for current_page_num in range(0, total_page_num):
|
||||
# 数据偏移量
|
||||
pos = current_page_num * default_page_size
|
||||
qq_userinfo_response = get_user_qzone_info(default_page_size, pos)
|
||||
current_page_data = json.loads(qq_userinfo_response)["msglist"]
|
||||
if current_page_data:
|
||||
all_page_data.extend(current_page_data)
|
||||
time.sleep(0.02)
|
||||
qq_userinfo = json.dumps({"msglist": all_page_data}, ensure_ascii=False, indent=2)
|
||||
Tool.write_txt_file(WORKDIR, QZONE_MOMENTS_ALL, qq_userinfo)
|
||||
qzone_moments_all = Tool.read_txt_file(WORKDIR, QZONE_MOMENTS_ALL)
|
||||
|
||||
if not Tool.is_valid_json(qzone_moments_all):
|
||||
@ -81,7 +99,7 @@ def get_visible_moments_list():
|
||||
|
||||
|
||||
# 获取用户QQ空间相关信息
|
||||
def get_user_qzone_info(num):
|
||||
def get_user_qzone_info(page_size, offset=0):
|
||||
url = 'https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6'
|
||||
cookies = Request.cookies
|
||||
g_tk = LoginUtil.bkn(cookies.get('p_skey'))
|
||||
@ -109,8 +127,8 @@ def get_user_qzone_info(num):
|
||||
'uin': f'{qqNumber}',
|
||||
'ftype': '0',
|
||||
'sort': '0',
|
||||
'pos': '0',
|
||||
'num': f'{num}',
|
||||
'pos': f'{offset}',
|
||||
'num': f'{page_size}',
|
||||
'replynum': '100',
|
||||
'g_tk': f'{g_tk}',
|
||||
'callback': '_preloadCallback',
|
||||
|
@ -61,6 +61,7 @@ def show_author_info():
|
||||
|
||||
|
||||
def get_html_template():
|
||||
# HTML模板
|
||||
# HTML模板
|
||||
html_template = """
|
||||
<!DOCTYPE html>
|
||||
@ -116,6 +117,7 @@ def get_html_template():
|
||||
max-width: 33vw;
|
||||
max-height: 33vh;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
}}
|
||||
.comments {{
|
||||
margin-top: 5px; /* 调整这里的值来减少间距 */
|
||||
@ -147,7 +149,14 @@ def get_html_template():
|
||||
<body>
|
||||
|
||||
{posts}
|
||||
|
||||
<script>
|
||||
// 为所有图片添加点击事件
|
||||
document.querySelectorAll(".image img").forEach(img => {{
|
||||
img.addEventListener("click", function() {{
|
||||
window.open(this.src, '_blank'); // 打开图片链接并在新标签页中展示
|
||||
}});
|
||||
}});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user