This commit is contained in:
LibraHp_0928 2024-11-02 17:20:29 +08:00
parent eeb8cd62d7
commit 4543dc479e
4 changed files with 198 additions and 151 deletions

1
.gitignore vendored
View File

@ -160,6 +160,7 @@ cython_debug/
#.idea/
myenv
results
# 导出结果文件夹
[0-9]*/
log.txt

View File

@ -13,6 +13,15 @@ RUN python -m venv /app/.venv && \
/app/.venv/bin/pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip && \
/app/.venv/bin/pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt
# 使用阿里云的 Debian 镜像源
RUN echo 'deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib\n\
deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib\n\
deb http://mirrors.aliyun.com/debian-security bullseye-security main\n\
deb-src http://mirrors.aliyun.com/debian-security bullseye-security main\n\
deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib\n\
deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib' > /etc/apt/sources.list
# 安装必要的库
RUN apt-get update && apt-get install -y libgtk-3-0
# 安装 NGINX

164
main.py
View File

@ -37,14 +37,15 @@ interact_counter = []
# 初始化当前登录用户
now_login_user = None
# 初始化交互排行榜
most_interactive_user = None
most_interactive_user = {}
# 初始化保存路径
save_path = None
save_path = ''
# 日志组件引用
log_info_ref = ft.Ref[ft.Text]()
# 全局page
global_page = ft.Page
# 空间登录链接
qzone_link = ''
# 全局header
headers = {
'authority': 'user.qzone.qq.com',
@ -65,6 +66,7 @@ headers = {
'Safari/537.36 Edg/121.0.0.0',
}
def bkn(pSkey):
# 计算bkn
@ -129,6 +131,7 @@ def parse_time_strings(time_str):
except ValueError:
return datetime.now() # 如果解析失败,返回最早的时间
def get_big_img_dlg(img_url):
return ft.AlertDialog(
modal=False,
@ -140,6 +143,7 @@ def get_big_img_dlg(img_url):
),
)
def log(message, type="info"):
now = time.strftime("%Y-%m-%d %H:%M:%S")
log_info_ref.current.value = f"[{now}] - [{type}] {message}"
@ -150,7 +154,6 @@ def log(message,type="info"):
f.write(f"[{now}] - {message}\n")
if type == "success":
# 开头添加[success]
log_info_ref.current.color = "green"
elif type == "error":
log_info_ref.current.color = "red"
@ -258,7 +261,7 @@ class PaginatedContainer(ft.Column):
[
ft.Row(
controls=[
ft.Text(self.title, size=20, weight="bold"),
ft.Text(self.title, size=20, weight=ft.FontWeight.BOLD),
ft.Row(
controls=[
ft.Text("导出为"),
@ -337,7 +340,6 @@ class PaginatedContainer(ft.Column):
except Exception as e:
log(e, "error")
def export_excel(self, e):
export_data = []
for item in self.data:
@ -367,7 +369,6 @@ class PaginatedContainer(ft.Column):
except Exception as e:
log(e, "error")
def export_html(self, e):
# HTML 头部和样式
html_start = '''
@ -503,8 +504,6 @@ class PaginatedContainer(ft.Column):
except Exception as e:
log(f"导出失败 {e}", "error")
def export_markdown(self, e):
# 创建 Markdown 内容的列表
markdown_lines = []
@ -543,12 +542,10 @@ class PaginatedContainer(ft.Column):
print(traceback.format_exc())
log(e, "error")
def did_mount(self):
"""This method is called when the control is added to the page."""
self.update_page_info()
def update_page_info(self):
# 更新当前页的内容
self.load_page_data()
@ -583,7 +580,7 @@ class PaginatedContainer(ft.Column):
ft.Image(src=item.avatar_url, fit=ft.ImageFit.COVER, border_radius=100),
ft.Column(
controls=[
ft.Text(item.username, size=18, weight="bold"),
ft.Text(item.username, size=18, weight=ft.FontWeight.BOLD),
ft.Text(f'QQ: {item.uin}', size=14),
ft.Text(item.link, size=12, color=ft.colors.BLUE_500),
],
@ -603,7 +600,7 @@ class PaginatedContainer(ft.Column):
ft.Image(src=item.user.avatar_url, fit=ft.ImageFit.COVER, border_radius=100),
ft.Column(
controls=[
ft.Text(item.user.username, size=18, weight="bold"),
ft.Text(item.user.username, size=18, weight=ft.FontWeight.BOLD),
ft.Text(f'{item.time}', size=14),
ft.Text(item.content, size=16, width=300),
],
@ -615,11 +612,16 @@ class PaginatedContainer(ft.Column):
# 如果存在图片,添加到 controls 中
if item.images and 'http' in item.images:
image_control = ft.PopupMenuButton(
content=ft.Image(src=item.images, fit=ft.ImageFit.FIT_WIDTH,height=300,width=300,border_radius=10),
content=ft.Image(src=item.images, fit=ft.ImageFit.FIT_WIDTH, height=300, width=300,
border_radius=10),
items=[
ft.PopupMenuItem(text="复制图片链接", on_click=lambda e, current_item=item: cb.copy(current_item.images)),
ft.PopupMenuItem(text="保存图片", on_click=lambda e, current_item=item: save_image(current_item.images, str(current_item.time))),
ft.PopupMenuItem(text="查看大图", on_click=lambda e, current_item=item: self.page.open(get_big_img_dlg(current_item.images))),
ft.PopupMenuItem(text="复制图片链接",
on_click=lambda e, current_item=item: cb.copy(current_item.images)),
ft.PopupMenuItem(text="保存图片",
on_click=lambda e, current_item=item: save_image(current_item.images,
str(current_item.time))),
ft.PopupMenuItem(text="查看大图", on_click=lambda e, current_item=item: self.page.open(
get_big_img_dlg(current_item.images))),
],
tooltip="显示操作",
)
@ -627,7 +629,8 @@ class PaginatedContainer(ft.Column):
# 如果存在评论,添加到 controls 中
if item.comment:
controls[1].controls.append(ft.Text(f'{item.comment.content}', size=12, color=ft.colors.BLUE_700,width=300))
controls[1].controls.append(
ft.Text(f'{item.comment.content}', size=12, color=ft.colors.BLUE_700, width=300))
card = ft.Card(
content=ft.Row(
@ -663,7 +666,6 @@ class PaginatedContainer(ft.Column):
# 最终将所有卡片的布局添加到 content_area
self.content_area.controls.append(rows)
def next_page(self, e):
if self.current_page < self.total_pages:
self.current_page += 1
@ -674,6 +676,7 @@ class PaginatedContainer(ft.Column):
self.current_page -= 1
self.update_page_info()
class User:
def __init__(self, uin, username):
self.uin = str(uin) # 将 uin 转换为字符串
@ -700,13 +703,15 @@ class Message:
def reset_save_content():
global all_messages, user_says, forward, leaves, other, friends
global all_messages, user_says, forward, leaves, other, friends, most_interactive_user, interact_counter
all_messages = []
user_says = []
forward = []
leaves = []
other = []
friends = []
most_interactive_user = {}
interact_counter = {}
def main(page: ft.Page):
@ -727,7 +732,8 @@ def main(page: ft.Page):
def logout():
page.session.clear()
user_info.content.controls[0].src = "https://raw.gitmirror.com/LibraHp/GetQzonehistory/refs/heads/gui/assets/logo.jpg"
user_info.content.controls[
0].src = "https://raw.gitmirror.com/LibraHp/GetQzonehistory/refs/heads/gui/assets/logo.jpg"
user_info.content.controls[1].value = "LibraHp"
global now_login_user
now_login_user = None
@ -738,7 +744,6 @@ def main(page: ft.Page):
tab.disabled = True
page.update()
def handle_close(e):
page.close(dlg_modal)
if e.control.text == "Yes":
@ -754,6 +759,7 @@ def main(page: ft.Page):
],
actions_alignment=ft.MainAxisAlignment.END
)
def QR():
# 获取 qq空间 二维码
url = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=3&d=72&v=4&t=0.8692955245720428&daid=5&pt_3rd_aid=0'
@ -782,7 +788,8 @@ def main(page: ft.Page):
cookies = page.session.get("user_cookies")
g_tk = bkn(cookies['p_skey'])
uin = re.sub(r'o0*', '', cookies.get('uin'))
response = requests.get('https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?g_tk=' + str(g_tk) + '&uins=' + uin,
response = requests.get(
'https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?g_tk=' + str(g_tk) + '&uins=' + uin,
headers=headers, cookies=cookies)
info = response.content.decode('GBK')
info = info.strip().lstrip('portraitCallBack(').rstrip(');')
@ -829,11 +836,16 @@ def main(page: ft.Page):
# 如果存在图片,添加到 controls 中
if item.images and 'http' in item.images:
image_control = ft.PopupMenuButton(
content=ft.Image(src=item.images, fit=ft.ImageFit.FIT_WIDTH, height=300, width=300, border_radius=10),
content=ft.Image(src=item.images, fit=ft.ImageFit.FIT_WIDTH, height=300, width=300,
border_radius=10),
items=[
ft.PopupMenuItem(text="复制图片链接", on_click=lambda e, current_item=item: cb.copy(current_item.images)),
ft.PopupMenuItem(text="保存图片", on_click=lambda e, current_item=item: save_image(current_item.images, str(current_item.time))),
ft.PopupMenuItem(text="查看大图", on_click=lambda e, current_item=item: page.open(get_big_img_dlg(current_item.images))),
ft.PopupMenuItem(text="复制图片链接",
on_click=lambda e, current_item=item: cb.copy(current_item.images)),
ft.PopupMenuItem(text="保存图片",
on_click=lambda e, current_item=item: save_image(current_item.images,
str(current_item.time))),
ft.PopupMenuItem(text="查看大图", on_click=lambda e, current_item=item: page.open(
get_big_img_dlg(current_item.images))),
],
tooltip="显示操作",
)
@ -864,7 +876,6 @@ def main(page: ft.Page):
content.visible = True
return progress_bar, login_text
def create_user_dir():
global save_path
try:
@ -905,13 +916,12 @@ def main(page: ft.Page):
print(traceback.format_exc())
log(f"创建用户目录时发生错误: {e}", "error")
# 获取内容页面
def create_get_content_page():
if page.session.contains_key("user_cookies"):
return get_message_result()
base64_image = QR()
# 更新二维码状态的函数(模拟,需实际实现逻辑)
def update_qr_code_status(e):
ptqrtoken = ptqrToken(page.session.get("qrsig"))
@ -942,6 +952,8 @@ def main(page: ft.Page):
'&s_url=https%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&f_url=&ptlang' \
'=2052&ptredirect=100&aid=549000912&daid=5&j_later=0&low_login_hour=0&regmaster=0&pt_login_type' \
'=3&pt_aid=0&pt_aaid=16&pt_light=0&pt_3rd_aid=0'
global qzone_link
qzone_link = url
try:
r = requests.get(url, cookies=cookies, allow_redirects=False)
target_cookies = requests.utils.dict_from_cookiejar(r.cookies)
@ -973,6 +985,7 @@ def main(page: ft.Page):
qr_image = ft.Image(src_base64=base64_image, width=200, height=200, fit=ft.ImageFit.CONTAIN, data='not_login')
qr_status = ft.Text("二维码状态:等待扫描", size=16, color="green", data='not_login')
def task():
while True:
# 使用 in 分别检查多个条件
@ -981,14 +994,14 @@ def main(page: ft.Page):
log(qr_status.value)
update_qr_code_status(None)
time.sleep(2)
thread = threading.Thread(target=task)
thread.start()
# 返回一个包含二维码和状态更新的布局
return ft.Column(
controls=[
ft.Text("请使用手机QQ扫码登录", size=24, weight="bold", data='not_login'),
ft.Text("请使用手机QQ扫码登录", size=24, weight=ft.FontWeight.BOLD, data='not_login'),
qr_image, # 展示二维码
qr_status, # 展示二维码状态
ft.Row(
@ -999,12 +1012,13 @@ def main(page: ft.Page):
alignment=ft.MainAxisAlignment.CENTER,
data='not_login'
),
ft.Image(src="https://raw.gitmirror.com/LibraHp/GetQzonehistory/refs/heads/gui/assets/loading.gif", expand=True, data='login_pic', visible=False),
ft.Text("获取空间消息中...", size=24, weight="bold", data='login_text',visible=False),
ft.Image(src="https://raw.gitmirror.com/LibraHp/GetQzonehistory/refs/heads/gui/assets/loading.gif",
expand=True, data='login_pic', visible=False),
ft.Text("获取空间消息中...", size=24, weight=ft.FontWeight.BOLD, data='login_text', visible=False),
ft.ProgressBar(data='login_progress', visible=False, bar_height=10, border_radius=10),
],
alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment="center",
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
expand=True,
)
@ -1046,6 +1060,7 @@ def main(page: ft.Page):
return response
def get_message_count():
total = 10
try:
# 初始的总量范围
lower_bound = 0
@ -1069,7 +1084,6 @@ def main(page: ft.Page):
log(e, "error")
return total
def get_hitokoto():
try:
url = "https://v1.hitokoto.cn/"
@ -1124,7 +1138,8 @@ def main(page: ft.Page):
friend_element = element.find('a', class_='f-name q_namecard')
if friend_element:
friend_name = friend_element.get_text()
friend_qq = friend_element.get('link', '')[9:] if friend_element.get('link', '') else '123456' # 使用默认空值
friend_qq = friend_element.get('link', '')[9:] if friend_element.get('link',
'') else '123456' # 使用默认空值
friend = User(uin=friend_qq, username=friend_name)
comment.user = friend
res_message.user = friend
@ -1144,7 +1159,8 @@ def main(page: ft.Page):
# 评论
if comment_element:
comment_time_element = comment_element.find('span', class_='ui-mr10 state')
comment.time = parse_time_strings(comment_time_element.get_text()) if comment_time_element else None
comment.time = parse_time_strings(
comment_time_element.get_text()) if comment_time_element else None
comment.content = comment_element.get_text()
res_message.comment = comment
@ -1188,14 +1204,14 @@ def main(page: ft.Page):
print(traceback.format_exc())
log(f"获取消息时发生错误: {e}", "error")
def get_message_result():
# 用户信息栏
user_info = ft.Card(
content=ft.Container(
content=ft.Column(
controls=[
ft.Row([
ft.Row(
controls=[
ft.CircleAvatar(
foreground_image_src=now_login_user.avatar_url,
content=ft.Text(f"{now_login_user.username}"),
@ -1208,19 +1224,22 @@ def main(page: ft.Page):
],
alignment=ft.MainAxisAlignment.CENTER,
)
]),
],
alignment=ft.MainAxisAlignment.CENTER
),
ft.Divider(height=9, thickness=3),
# 操作栏
ft.Row(
controls=[
ft.Column(
controls=[
ft.ElevatedButton(text="空间网页版"),
ft.ElevatedButton(text="打开导出文件夹"),
ft.ElevatedButton(text="空间网页版", on_click=lambda _: page.launch_url(qzone_link)),
ft.ElevatedButton(text="打开文件夹"),
],
),
ft.Column(
controls=[
ft.ElevatedButton(text="重新获取"),
ft.ElevatedButton(text="重新获取内容"),
ft.ElevatedButton(text="保存登录状态"),
],
),
@ -1237,18 +1256,34 @@ def main(page: ft.Page):
col=4
)
# 交互信息栏
interaction_info = ft.Card(
content=ft.Container(
content=ft.Column(
[
ft.Text("自空间交互以来:", size=24, weight=ft.FontWeight.BOLD),
ft.Text(f"你发布了", size=20, spans=[ft.TextSpan(f" {user_says.__len__() } ", ft.TextStyle(weight=ft.FontWeight.BOLD,color=ft.colors.BLUE_300)),ft.TextSpan("条说说", ft.TextStyle(size=20))]),
ft.Text(f"", size=20, spans=[ft.TextSpan(f" {leaves.__len__() } ", ft.TextStyle(weight=ft.FontWeight.BOLD,color=ft.colors.BLUE_300)),ft.TextSpan("条留言", ft.TextStyle(size=20))]),
ft.Text(f"", size=20,spans=[ft.TextSpan(f" {friends.__len__() } ", ft.TextStyle(weight=ft.FontWeight.BOLD,color=ft.colors.BLUE_300)),ft.TextSpan("个人与你空间有过交互", ft.TextStyle(size=20))]),
ft.Text(f"最早的说说发布在", size=20, spans=[ft.TextSpan(f" {user_says[user_says.__len__() - 1].time if user_says.__len__() > 0 else ''} ", ft.TextStyle(weight=ft.FontWeight.BOLD,color=ft.colors.BLUE_300)),ft.TextSpan(",那个时候的你有这么多烦恼嘛", ft.TextStyle(size=20))]),
ft.Text(f"和你交互最多的人是", size=20, spans=[ft.TextSpan(f" @{most_interactive_user[0][0][0] if most_interactive_user.__len__() > 0 else ''} ", ft.TextStyle(weight=ft.FontWeight.BOLD,color=ft.colors.BLUE_300)),ft.TextSpan("现在的她/他怎么样了呢", ft.TextStyle(size=20))]),
ft.Text(f"你发布了", size=20, spans=[ft.TextSpan(f" {user_says.__len__()} ",
ft.TextStyle(weight=ft.FontWeight.BOLD,
color=ft.colors.BLUE_300)),
ft.TextSpan("条说说", ft.TextStyle(size=20))]),
ft.Text(f"", size=20, spans=[ft.TextSpan(f" {leaves.__len__()} ",
ft.TextStyle(weight=ft.FontWeight.BOLD,
color=ft.colors.BLUE_300)),
ft.TextSpan("条留言", ft.TextStyle(size=20))]),
ft.Text(f"", size=20, spans=[ft.TextSpan(f" {friends.__len__()} ",
ft.TextStyle(weight=ft.FontWeight.BOLD,
color=ft.colors.BLUE_300)),
ft.TextSpan("个人与你空间有过交互", ft.TextStyle(size=20))]),
ft.Text(f"最早的说说发布在", size=20, spans=[ft.TextSpan(
f" {user_says[user_says.__len__() - 1].time if user_says.__len__() > 0 else ''} ",
ft.TextStyle(weight=ft.FontWeight.BOLD, color=ft.colors.BLUE_300)),
ft.TextSpan(",那个时候的你有这么多烦恼嘛",
ft.TextStyle(size=20))]),
ft.Text(f"和你交互最多的人是", size=20, spans=[ft.TextSpan(
f" @{most_interactive_user[0][0][0] if most_interactive_user.__len__() > 0 else ''} ",
ft.TextStyle(weight=ft.FontWeight.BOLD, color=ft.colors.BLUE_300)),
ft.TextSpan("现在的她/他怎么样了呢",
ft.TextStyle(size=20))]),
],
spacing=10,
alignment=ft.MainAxisAlignment.CENTER,
@ -1259,7 +1294,6 @@ def main(page: ft.Page):
col=8
)
hitokoto, source = get_hitokoto()
# 发布的第一条说说
first_post = ft.Container(
@ -1269,13 +1303,16 @@ def main(page: ft.Page):
ft.Container(
content=ft.ResponsiveRow(
controls=[
ft.Text(f"{user_says[user_says.__len__() - 1].time if user_says.__len__() > 0 else ''}", size=14),
ft.Text(f"{user_says[user_says.__len__() - 1].content if user_says.__len__() > 0 else ''}", size=20)
ft.Text(
f"{user_says[user_says.__len__() - 1].time if user_says.__len__() > 0 else ''}",
size=14),
ft.Text(
f"{user_says[user_says.__len__() - 1].content if user_says.__len__() > 0 else ''}",
size=20)
]
),
padding=10,
border_radius=ft.border_radius.all(5),
# bgcolor=ft.colors.GREY_100,
expand=True,
),
ft.Text(f"一言: {hitokoto}\n出自: {source}", size=14)
@ -1306,7 +1343,8 @@ def main(page: ft.Page):
ft.Row(
controls=[
ft.Text(f"{index + 1}.", size=14),
ft.Image(src=f'http://q1.qlogo.cn/g?b=qq&nk={item[0][1]}&s=100', width=40, height=40, border_radius=100),
ft.Image(src=f'http://q1.qlogo.cn/g?b=qq&nk={item[0][1]}&s=100', width=40, height=40,
border_radius=100),
ft.Text(f"@{item[0][0]} 交互{item[1]}", size=14)
]
)
@ -1334,22 +1372,21 @@ def main(page: ft.Page):
expand=True,
)
# 用户信息
user_info = ft.Container(
content=ft.Column(
controls=[
ft.Image(src="https://raw.gitmirror.com/LibraHp/GetQzonehistory/refs/heads/gui/assets/logo.jpg", width=80, height=80, border_radius=100), # Replace with actual avatar URL
ft.Text("LibraHp", size=20, weight="bold")
ft.Image(src="https://raw.gitmirror.com/LibraHp/GetQzonehistory/refs/heads/gui/assets/logo.jpg",
width=80, height=80, border_radius=100), # Replace with actual avatar URL
ft.Text("LibraHp", size=20, weight=ft.FontWeight.BOLD)
],
alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment="center"
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
),
width=200,
padding=20
)
# 左侧标签页
tabs = ft.Column(
controls=[
@ -1363,7 +1400,7 @@ def main(page: ft.Page):
ft.ElevatedButton("退出当前账号登录", on_click=change_route, data="Logout", width=page.width),
ft.TextButton("Powered by LibraHp", url="https://github.com/LibraHp", data="Github", width=page.width)
],
alignment="center",
alignment=ft.alignment.center,
spacing=10
)
@ -1372,7 +1409,7 @@ def main(page: ft.Page):
content=ft.Column(
controls=[user_info, tabs],
spacing=20,
horizontal_alignment="center",
horizontal_alignment=ft.alignment.center,
scroll=ft.ScrollMode.HIDDEN,
),
alignment=ft.alignment.center,
@ -1400,7 +1437,6 @@ def main(page: ft.Page):
expand=True,
scroll=ft.ScrollMode.HIDDEN
),
# bgcolor="#ffffff",
expand=True,
padding=20,
border_radius=10,
@ -1411,7 +1447,7 @@ def main(page: ft.Page):
main_layout = ft.ResponsiveRow(
controls=[left_panel, content_area],
expand=True,
alignment="start"
# alignment="start"
)
log_list = ft.Text(ref=log_info_ref, size=12, color="blue")

View File

@ -2,3 +2,4 @@ beautifulsoup4==4.12.2
flet==0.24.1
pandas==2.2.3
Requests==2.31.0
openpyxl==3.1.5