mirror of
https://github.com/LibraHp/GetQzonehistory.git
synced 2025-01-04 03:09:09 +00:00
完成基本功能
This commit is contained in:
parent
61d5c6bed3
commit
a627fab6c7
107
main.py
107
main.py
@ -18,8 +18,11 @@ friends = []
|
|||||||
forward = []
|
forward = []
|
||||||
# 初始化留言列表
|
# 初始化留言列表
|
||||||
leaves = []
|
leaves = []
|
||||||
|
# 初始换其他列表
|
||||||
other = []
|
other = []
|
||||||
|
|
||||||
|
now_login_user = None
|
||||||
|
|
||||||
# 全局header
|
# 全局header
|
||||||
headers = {
|
headers = {
|
||||||
'authority': 'user.qzone.qq.com',
|
'authority': 'user.qzone.qq.com',
|
||||||
@ -102,19 +105,27 @@ def parse_time_strings(time_str):
|
|||||||
|
|
||||||
|
|
||||||
def clean_content():
|
def clean_content():
|
||||||
global all_messages, user_says, forward, leaves, other, friends
|
global all_messages, user_says, forward, leaves, other, friends, now_login_user
|
||||||
# 好友去重
|
# 好友去重
|
||||||
friends = list({item.uin: item for item in friends}.values())
|
friends = list({item.uin: item for item in friends}.values())
|
||||||
|
all_messages = list({item.content: item for item in all_messages}.values())
|
||||||
for message in all_messages:
|
for message in all_messages:
|
||||||
|
try:
|
||||||
message_type = message.type
|
message_type = message.type
|
||||||
if '留言' in message_type:
|
if '留言' in message_type:
|
||||||
|
message.content = message.content.replace(now_login_user.username, '')
|
||||||
leaves.append(message)
|
leaves.append(message)
|
||||||
elif '赞' in message_type:
|
elif now_login_user.username in message.content:
|
||||||
|
message.user = now_login_user
|
||||||
|
message.content = message.content.replace(now_login_user.username + ' :', '')
|
||||||
user_says.append(message)
|
user_says.append(message)
|
||||||
elif '转发' in message_type:
|
elif '转发' in message_type:
|
||||||
forward.append(message)
|
forward.append(message)
|
||||||
else:
|
else:
|
||||||
other.append(message)
|
other.append(message)
|
||||||
|
message.content = message.content.replace(message.user.username + ' :', '')
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
class PaginatedContainer(ft.UserControl):
|
class PaginatedContainer(ft.UserControl):
|
||||||
@ -142,8 +153,9 @@ class PaginatedContainer(ft.UserControl):
|
|||||||
ft.Row(
|
ft.Row(
|
||||||
controls=[
|
controls=[
|
||||||
ft.Text(self.title, size=20,weight="bold"),
|
ft.Text(self.title, size=20,weight="bold"),
|
||||||
|
ft.ElevatedButton("导出"),
|
||||||
],
|
],
|
||||||
alignment=ft.MainAxisAlignment.CENTER,
|
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
|
||||||
),
|
),
|
||||||
# 主要内容区域
|
# 主要内容区域
|
||||||
ft.Container(
|
ft.Container(
|
||||||
@ -163,7 +175,7 @@ class PaginatedContainer(ft.UserControl):
|
|||||||
alignment=ft.MainAxisAlignment.CENTER,
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
spacing=20,
|
spacing=20,
|
||||||
),
|
),
|
||||||
height=20,
|
height=30,
|
||||||
alignment=ft.alignment.center,
|
alignment=ft.alignment.center,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -200,7 +212,8 @@ class PaginatedContainer(ft.UserControl):
|
|||||||
row_count = 0
|
row_count = 0
|
||||||
|
|
||||||
for index, item in enumerate(current_data):
|
for index, item in enumerate(current_data):
|
||||||
# 创建每个 Card
|
if isinstance(item, User):
|
||||||
|
# 创建 User Card
|
||||||
card = ft.Card(
|
card = ft.Card(
|
||||||
content=ft.Row(
|
content=ft.Row(
|
||||||
controls=[
|
controls=[
|
||||||
@ -212,7 +225,6 @@ class PaginatedContainer(ft.UserControl):
|
|||||||
ft.Text(item.link, size=12, color=ft.colors.BLUE_500),
|
ft.Text(item.link, size=12, color=ft.colors.BLUE_500),
|
||||||
],
|
],
|
||||||
alignment=ft.MainAxisAlignment.CENTER,
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
# horizontal_alignment=ft.CrossAxisAlignment.CENTER,
|
|
||||||
spacing=4,
|
spacing=4,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@ -222,6 +234,38 @@ class PaginatedContainer(ft.UserControl):
|
|||||||
),
|
),
|
||||||
expand=True,
|
expand=True,
|
||||||
)
|
)
|
||||||
|
elif isinstance(item, Message):
|
||||||
|
# 创建 Message Card
|
||||||
|
controls = [
|
||||||
|
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(f'{item.time}', size=14),
|
||||||
|
ft.Text(item.content, size=12,width=300),
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
|
spacing=4,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
# 如果存在图片,添加到 controls 中
|
||||||
|
if item.images:
|
||||||
|
controls[1].controls.append(ft.Image(src=item.images, fit=ft.ImageFit.COVER,height=300,width=300))
|
||||||
|
|
||||||
|
# 如果存在评论,添加到 controls 中
|
||||||
|
if item.comment:
|
||||||
|
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(
|
||||||
|
controls=controls,
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
|
spacing=10,
|
||||||
|
expand=True
|
||||||
|
),
|
||||||
|
expand=True,
|
||||||
|
)
|
||||||
|
|
||||||
# 将 Card 添加到当前行
|
# 将 Card 添加到当前行
|
||||||
current_row.controls.append(card)
|
current_row.controls.append(card)
|
||||||
@ -246,6 +290,7 @@ class PaginatedContainer(ft.UserControl):
|
|||||||
self.content_area.controls.append(rows)
|
self.content_area.controls.append(rows)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def next_page(self, e):
|
def next_page(self, e):
|
||||||
if self.current_page < self.total_pages:
|
if self.current_page < self.total_pages:
|
||||||
self.current_page += 1
|
self.current_page += 1
|
||||||
@ -295,29 +340,6 @@ class Message:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_card(img_url, title, subtitle):
|
|
||||||
return ft.Card(
|
|
||||||
content=ft.Container(
|
|
||||||
content=ft.Column(
|
|
||||||
[
|
|
||||||
ft.ListTile(
|
|
||||||
# 如果img_url为空 显示https://picsum.photos/200
|
|
||||||
# leading=ft.Image(src=img_url, border_radius=100),
|
|
||||||
title=ft.Text(title),
|
|
||||||
subtitle=ft.Text(subtitle),
|
|
||||||
),
|
|
||||||
# ft.Row(
|
|
||||||
# [ft.TextButton("购票"), ft.TextButton("试听")],
|
|
||||||
# alignment=ft.MainAxisAlignment.END,
|
|
||||||
# ),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
expand=True,
|
|
||||||
padding=10,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main(page: ft.Page):
|
def main(page: ft.Page):
|
||||||
page.window.center()
|
page.window.center()
|
||||||
page.title = "QQ空间历史内容获取 v1.0 Powered by LibraHp"
|
page.title = "QQ空间历史内容获取 v1.0 Powered by LibraHp"
|
||||||
@ -335,6 +357,8 @@ def main(page: ft.Page):
|
|||||||
page.session.clear()
|
page.session.clear()
|
||||||
user_info.content.controls[0].src = "assets/logo.jpg"
|
user_info.content.controls[0].src = "assets/logo.jpg"
|
||||||
user_info.content.controls[1].value = "LibraHp"
|
user_info.content.controls[1].value = "LibraHp"
|
||||||
|
global now_login_user
|
||||||
|
now_login_user = None
|
||||||
content_area.content = create_get_content_page()
|
content_area.content = create_get_content_page()
|
||||||
for tab in tabs.controls:
|
for tab in tabs.controls:
|
||||||
if tab.data != "GetContent" and tab.data != "Logout" and tab.data != "Github":
|
if tab.data != "GetContent" and tab.data != "Logout" and tab.data != "Github":
|
||||||
@ -391,6 +415,8 @@ def main(page: ft.Page):
|
|||||||
info = json.loads(info)
|
info = json.loads(info)
|
||||||
user_info.content.controls[0].src = f'http://q1.qlogo.cn/g?b=qq&nk={uin}&s=100'
|
user_info.content.controls[0].src = f'http://q1.qlogo.cn/g?b=qq&nk={uin}&s=100'
|
||||||
user_info.content.controls[1].value = info[uin][6]
|
user_info.content.controls[1].value = info[uin][6]
|
||||||
|
global now_login_user
|
||||||
|
now_login_user = User(uin,info[uin][6])
|
||||||
page.update()
|
page.update()
|
||||||
|
|
||||||
# 路由改变函数
|
# 路由改变函数
|
||||||
@ -399,15 +425,15 @@ def main(page: ft.Page):
|
|||||||
if selected_tab == "GetContent":
|
if selected_tab == "GetContent":
|
||||||
content_area.content = create_get_content_page()
|
content_area.content = create_get_content_page()
|
||||||
elif selected_tab == "User":
|
elif selected_tab == "User":
|
||||||
content_area.content = ft.Text("说说列表", size=30)
|
content_area.content = PaginatedContainer(user_says, items_per_page=2,title="说说列表")
|
||||||
elif selected_tab == "Leave":
|
elif selected_tab == "Leave":
|
||||||
content_area.content = ft.Text("留言列表", size=30)
|
content_area.content = PaginatedContainer(leaves, items_per_page=1,title="留言列表")
|
||||||
elif selected_tab == "Friends":
|
elif selected_tab == "Friends":
|
||||||
content_area.content = PaginatedContainer(friends, items_per_page=6,title="好友列表")
|
content_area.content = PaginatedContainer(friends, items_per_page=4,title="好友列表")
|
||||||
elif selected_tab == "Forward":
|
elif selected_tab == "Forward":
|
||||||
content_area.content = ft.Text("转发列表", size=30)
|
content_area.content = PaginatedContainer(forward, items_per_page=2,title="转发列表")
|
||||||
elif selected_tab == "Other":
|
elif selected_tab == "Other":
|
||||||
content_area.content = ft.Text("其他列表", size=30)
|
content_area.content = PaginatedContainer(other, items_per_page=2,title="其他列表")
|
||||||
elif selected_tab == "Pictures":
|
elif selected_tab == "Pictures":
|
||||||
content_area.content = ft.Text("图片列表", size=30)
|
content_area.content = ft.Text("图片列表", size=30)
|
||||||
elif selected_tab == "Logout":
|
elif selected_tab == "Logout":
|
||||||
@ -472,8 +498,7 @@ def main(page: ft.Page):
|
|||||||
r = requests.get(url, cookies=cookies, allow_redirects=False)
|
r = requests.get(url, cookies=cookies, allow_redirects=False)
|
||||||
target_cookies = requests.utils.dict_from_cookiejar(r.cookies)
|
target_cookies = requests.utils.dict_from_cookiejar(r.cookies)
|
||||||
page.session.set("user_cookies", target_cookies)
|
page.session.set("user_cookies", target_cookies)
|
||||||
page.snack_bar = ft.SnackBar(ft.Text(f"登录成功,欢迎您 {target_cookies.get('uin')}"),duration=2000)
|
log(f"登录成功,欢迎您,{page.session.get('user_cookies')['uin']}", "success")
|
||||||
page.snack_bar.open = True
|
|
||||||
get_login_user_info()
|
get_login_user_info()
|
||||||
progress_bar, login_text = show_login_content()
|
progress_bar, login_text = show_login_content()
|
||||||
create_card_list_view(progress_bar, login_text)
|
create_card_list_view(progress_bar, login_text)
|
||||||
@ -592,6 +617,7 @@ def main(page: ft.Page):
|
|||||||
login_text.value = "获取空间消息列表中..."
|
login_text.value = "获取空间消息列表中..."
|
||||||
page.update()
|
page.update()
|
||||||
for i in range(int(count / 100) + 1):
|
for i in range(int(count / 100) + 1):
|
||||||
|
try:
|
||||||
message = get_message(i * 100, 100).content.decode('utf-8')
|
message = get_message(i * 100, 100).content.decode('utf-8')
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
html = process_old_html(message)
|
html = process_old_html(message)
|
||||||
@ -649,7 +675,12 @@ def main(page: ft.Page):
|
|||||||
# progress_bar.value = round(progress_bar.value, 2)
|
# progress_bar.value = round(progress_bar.value, 2)
|
||||||
log(f'当前进度:{round(i / int(count / 100), 3) * 100}%')
|
log(f'当前进度:{round(i / int(count / 100), 3) * 100}%')
|
||||||
page.update()
|
page.update()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
log(e)
|
||||||
|
continue
|
||||||
login_text.value = "获取成功!"
|
login_text.value = "获取成功!"
|
||||||
|
log("获取成功!", "success")
|
||||||
progress_bar.visible = False
|
progress_bar.visible = False
|
||||||
clean_content()
|
clean_content()
|
||||||
unlock_tabs()
|
unlock_tabs()
|
||||||
@ -742,7 +773,7 @@ def main(page: ft.Page):
|
|||||||
),
|
),
|
||||||
ft.Row(
|
ft.Row(
|
||||||
controls=[
|
controls=[
|
||||||
ft.Text("最早的说说发布在 2022 年 3 月 20 日 12:00", size=20),
|
ft.Text(f"最早的说说发布在{all_messages[0].time}", size=20),
|
||||||
ft.Text("程序完全免费,请勿用于商业用途!", size=20),
|
ft.Text("程序完全免费,请勿用于商业用途!", size=20),
|
||||||
],
|
],
|
||||||
alignment="center",
|
alignment="center",
|
||||||
|
Loading…
Reference in New Issue
Block a user