|
|
@ -1,5 +1,7 @@
|
|
|
|
import csv
|
|
|
|
import csv
|
|
|
|
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import random
|
|
|
|
|
|
|
|
import tempfile
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
import tkinter as tk
|
|
|
|
import tkinter as tk
|
|
|
|
from io import BytesIO
|
|
|
|
from io import BytesIO
|
|
|
@ -13,6 +15,12 @@ import func_collec
|
|
|
|
import dis_collect
|
|
|
|
import dis_collect
|
|
|
|
class Mainpage:
|
|
|
|
class Mainpage:
|
|
|
|
def __init__(self,master,name):
|
|
|
|
def __init__(self,master,name):
|
|
|
|
|
|
|
|
self.c_data_index=0
|
|
|
|
|
|
|
|
self.c_image_index=0
|
|
|
|
|
|
|
|
self.c_content='暂无数据!'
|
|
|
|
|
|
|
|
self.c_image_max=0
|
|
|
|
|
|
|
|
self.c_data_max=0
|
|
|
|
|
|
|
|
|
|
|
|
self.content = ''
|
|
|
|
self.content = ''
|
|
|
|
self.time = ''
|
|
|
|
self.time = ''
|
|
|
|
self.collect = ''
|
|
|
|
self.collect = ''
|
|
|
@ -100,11 +108,101 @@ class Mainpage:
|
|
|
|
self.init_text()
|
|
|
|
self.init_text()
|
|
|
|
self.init_main_Page()
|
|
|
|
self.init_main_Page()
|
|
|
|
self.update_max()
|
|
|
|
self.update_max()
|
|
|
|
self.image_url(self.current_data_index, self.current_data_image_index)
|
|
|
|
self.image_url(self.current_data_image_index)
|
|
|
|
|
|
|
|
|
|
|
|
def to_like_page(self):
|
|
|
|
def to_like_page(self):
|
|
|
|
self.page.destroy()
|
|
|
|
data=0
|
|
|
|
self.init_like_page()
|
|
|
|
with open('collections/{}.csv'.format(self.user),'r+',newline='',encoding='utf-8') as f:
|
|
|
|
|
|
|
|
reader = csv.reader(f)
|
|
|
|
|
|
|
|
if len(list(reader))>0:
|
|
|
|
|
|
|
|
data=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if data==1:
|
|
|
|
|
|
|
|
self.c_data_index = 0
|
|
|
|
|
|
|
|
self.c_image_index = 0
|
|
|
|
|
|
|
|
self.c_content = '暂无数据!'
|
|
|
|
|
|
|
|
self.c_image_max = 0
|
|
|
|
|
|
|
|
self.c_data_max = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.page.destroy()
|
|
|
|
|
|
|
|
self.c_init_text()
|
|
|
|
|
|
|
|
self.init_like_page()
|
|
|
|
|
|
|
|
self.c_image_url()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.init_like_page()
|
|
|
|
|
|
|
|
def c_next_data(self):
|
|
|
|
|
|
|
|
if self.c_data_index+1 < self.c_data_max:
|
|
|
|
|
|
|
|
self.c_data_index += 1
|
|
|
|
|
|
|
|
self.c_image_index = 0
|
|
|
|
|
|
|
|
self.c_init_text()
|
|
|
|
|
|
|
|
self.init_like_page()
|
|
|
|
|
|
|
|
self.c_image_url()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
messagebox.showinfo(message='这是最后一篇')
|
|
|
|
|
|
|
|
def c_pre_data(self):
|
|
|
|
|
|
|
|
if self.c_data_index-1<0:
|
|
|
|
|
|
|
|
messagebox.showinfo(message='这是第一篇')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.c_data_index -= 1
|
|
|
|
|
|
|
|
self.c_image_index=0
|
|
|
|
|
|
|
|
self.c_init_text()
|
|
|
|
|
|
|
|
self.init_like_page()
|
|
|
|
|
|
|
|
self.c_image_url()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def c_image_url(self):
|
|
|
|
|
|
|
|
with open('collections/{}.csv'.format(self.user),'r+',encoding='utf-8') as f:
|
|
|
|
|
|
|
|
reader = csv.reader(f)
|
|
|
|
|
|
|
|
row =''
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
for rows in reader:
|
|
|
|
|
|
|
|
if i==self.c_data_index:
|
|
|
|
|
|
|
|
row=rows
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
self.load_image_from_url(self.page2,eval(row[2])[self.c_image_index])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def c_pre_image(self):
|
|
|
|
|
|
|
|
if self.c_image_index - 1 < 0:
|
|
|
|
|
|
|
|
messagebox.showinfo(title='提示', message='没有上一张了')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.c_image_index -= 1
|
|
|
|
|
|
|
|
self.c_image_url()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def c_next_image(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.c_image_index + 1 >= self.c_image_max:
|
|
|
|
|
|
|
|
messagebox.showinfo(message='这是最后一张')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.c_image_index += 1
|
|
|
|
|
|
|
|
self.c_image_url()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def c_init_text(self):
|
|
|
|
|
|
|
|
with open('collections/{}.csv'.format(self.user),'r+',encoding='utf-8') as f:
|
|
|
|
|
|
|
|
reader = csv.reader(f)
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
for row in reader:
|
|
|
|
|
|
|
|
i+=1
|
|
|
|
|
|
|
|
self.c_data_max=i
|
|
|
|
|
|
|
|
flag=0
|
|
|
|
|
|
|
|
with open('collections/{}.csv'.format(self.user),'r+',encoding='utf-8') as f:
|
|
|
|
|
|
|
|
reader = csv.reader(f)
|
|
|
|
|
|
|
|
if not next(reader):
|
|
|
|
|
|
|
|
self.c_content='暂无收藏数据'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flag=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if flag==1:
|
|
|
|
|
|
|
|
with open('collections/{}.csv'.format(self.user), 'r+', encoding='utf-8') as f:
|
|
|
|
|
|
|
|
reader = csv.reader(f)
|
|
|
|
|
|
|
|
index = 0
|
|
|
|
|
|
|
|
for row in reader:
|
|
|
|
|
|
|
|
if index == self.c_data_index:
|
|
|
|
|
|
|
|
title = row[1]
|
|
|
|
|
|
|
|
text = row[3].replace('<br/>', '\n').replace('.<br/>', '\n')
|
|
|
|
|
|
|
|
self.c_content = title + text
|
|
|
|
|
|
|
|
self.c_image_max=len(eval(row[2]))
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
|
|
|
|
def init_like_page(self):
|
|
|
|
def init_like_page(self):
|
|
|
|
self.page2=tk.Frame(self.root)
|
|
|
|
self.page2=tk.Frame(self.root)
|
|
|
@ -120,37 +218,25 @@ class Mainpage:
|
|
|
|
self.btn_exit.place(relx=0.9, rely=0.9, relheight=0.05, relwidth=0.07)
|
|
|
|
self.btn_exit.place(relx=0.9, rely=0.9, relheight=0.05, relwidth=0.07)
|
|
|
|
|
|
|
|
|
|
|
|
self.text = tk.Text(self.page2, bg='#ADD9FE', font=18)
|
|
|
|
self.text = tk.Text(self.page2, bg='#ADD9FE', font=18)
|
|
|
|
self.text.insert(tk.END, '收藏页面')
|
|
|
|
self.text.insert(tk.END, self.c_content)
|
|
|
|
self.text.config(state=tk.DISABLED, cursor='')
|
|
|
|
self.text.config(state=tk.DISABLED, cursor='')
|
|
|
|
self.text.place(relx=0.58, rely=0.07, relheight=0.86, relwidth=0.3)
|
|
|
|
self.text.place(relx=0.58, rely=0.07, relheight=0.86, relwidth=0.3)
|
|
|
|
|
|
|
|
|
|
|
|
self.btn_Image_pre = tk.Button(self.page2, text='上一张', bg='#D7EFFF',font=('SimHei',15,'bold'))
|
|
|
|
self.btn_Image_pre = tk.Button(self.page2, text='上一张', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.c_pre_image)
|
|
|
|
self.btn_Image_pre.place(relx=0.14, rely=0.01, relheight=0.05, relwidth=0.07)
|
|
|
|
self.btn_Image_pre.place(relx=0.14, rely=0.01, relheight=0.05, relwidth=0.07)
|
|
|
|
|
|
|
|
|
|
|
|
self.btn_Image_next = tk.Button(self.page2, text='下一张', bg='#D7EFFF',font=('SimHei',15,'bold'))
|
|
|
|
self.btn_Image_next = tk.Button(self.page2, text='下一张', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.c_next_image)
|
|
|
|
self.btn_Image_next.place(relx=0.24, rely=0.01, relheight=0.05, relwidth=0.07)
|
|
|
|
self.btn_Image_next.place(relx=0.24, rely=0.01, relheight=0.05, relwidth=0.07)
|
|
|
|
|
|
|
|
|
|
|
|
self.btn_next = tk.Button(self.page2, text='下一篇', bg='#D7EFFF',font=('SimHei',15,'bold'))
|
|
|
|
self.btn_next = tk.Button(self.page2, text='下一篇', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.c_next_data)
|
|
|
|
self.btn_next.place(relx=0.45, rely=0.45, relheight=0.08, relwidth=0.09)
|
|
|
|
self.btn_next.place(relx=0.45, rely=0.45, relheight=0.08, relwidth=0.09)
|
|
|
|
|
|
|
|
|
|
|
|
self.btn_pre = tk.Button(self.page2, text='上一篇', bg='#D7EFFF',font=('SimHei',15,'bold'))
|
|
|
|
self.btn_pre = tk.Button(self.page2, text='上一篇', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.c_pre_data)
|
|
|
|
self.btn_pre.place(relx=0.45, rely=0.35, relheight=0.08, relwidth=0.09)
|
|
|
|
self.btn_pre.place(relx=0.45, rely=0.35, relheight=0.08, relwidth=0.09)
|
|
|
|
|
|
|
|
|
|
|
|
self.btn_liked = tk.Button(self.page2, text='收藏攻略', bg='#D7EFFF',font=('SimHei',15,'bold'))
|
|
|
|
self.btn_dis_liked = tk.Button(self.page2, text='取消收藏', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.func_discollect)
|
|
|
|
self.btn_liked.place(relx=0.9, rely=0.2, relheight=0.05, relwidth=0.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.btn_dis_liked = tk.Button(self.page2, text='取消收藏', bg='#D7EFFF',font=('SimHei',15,'bold'))
|
|
|
|
|
|
|
|
self.btn_dis_liked.place(relx=0.9, rely=0.3, relheight=0.05, relwidth=0.1)
|
|
|
|
self.btn_dis_liked.place(relx=0.9, rely=0.3, relheight=0.05, relwidth=0.1)
|
|
|
|
|
|
|
|
|
|
|
|
self.lable_like = tk.Label(self.page2, text='喜欢人数:', font=('SimHei',15,'bold'))
|
|
|
|
|
|
|
|
self.lable_like.place(relx=0.05, rely=0.93)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.lable_like = tk.Label(self.page2, text='收藏人数:', font=('SimHei',15,'bold'))
|
|
|
|
|
|
|
|
self.lable_like.place(relx=0.17, rely=0.93)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.lable_like = tk.Label(self.page2, text='转发人数:', font=('SimHei',15,'bold'))
|
|
|
|
|
|
|
|
self.lable_like.place(relx=0.29, rely=0.93)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def notes_request(self,next_back):
|
|
|
|
def notes_request(self,next_back):
|
|
|
|
if next_back == 'next':
|
|
|
|
if next_back == 'next':
|
|
|
|
if self.current_data_index + 1 <= self.max_data_count:
|
|
|
|
if self.current_data_index + 1 <= self.max_data_count:
|
|
|
@ -261,7 +347,7 @@ class Mainpage:
|
|
|
|
messagebox.showinfo(message='这是最后一张')
|
|
|
|
messagebox.showinfo(message='这是最后一张')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.current_data_image_index += 1
|
|
|
|
self.current_data_image_index += 1
|
|
|
|
self.image_url(self.current_data_index, self.current_data_image_index)
|
|
|
|
self.image_url(self.current_data_image_index)
|
|
|
|
|
|
|
|
|
|
|
|
# 上一张图片
|
|
|
|
# 上一张图片
|
|
|
|
def pre_image(self):
|
|
|
|
def pre_image(self):
|
|
|
@ -280,6 +366,23 @@ class Mainpage:
|
|
|
|
messagebox.showinfo(title='提示', message='你还没有输入任何东西!')
|
|
|
|
messagebox.showinfo(title='提示', message='你还没有输入任何东西!')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if DataRequest.DataRequest(str(self.research.get())).success=='True':
|
|
|
|
if DataRequest.DataRequest(str(self.research.get())).success=='True':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.content = ''
|
|
|
|
|
|
|
|
self.time = ''
|
|
|
|
|
|
|
|
self.collect = ''
|
|
|
|
|
|
|
|
self.likes = ''
|
|
|
|
|
|
|
|
self.share = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.flag = 0
|
|
|
|
|
|
|
|
self.is_pre = 'False'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.current_data_index = 0
|
|
|
|
|
|
|
|
self.current_data_image_index = 0
|
|
|
|
|
|
|
|
self.current_notes_index = 0
|
|
|
|
|
|
|
|
self.max_data_count = 0
|
|
|
|
|
|
|
|
self.max_notes_count = 0
|
|
|
|
|
|
|
|
self.max_iamge_count = 0
|
|
|
|
|
|
|
|
|
|
|
|
self.data_request = DataRequest.DataRequest(str(self.research.get()))
|
|
|
|
self.data_request = DataRequest.DataRequest(str(self.research.get()))
|
|
|
|
time.sleep(random.uniform(0,1))
|
|
|
|
time.sleep(random.uniform(0,1))
|
|
|
|
self.init_notes_request()
|
|
|
|
self.init_notes_request()
|
|
|
@ -325,7 +428,7 @@ class Mainpage:
|
|
|
|
if self.csv_is_empty():
|
|
|
|
if self.csv_is_empty():
|
|
|
|
messagebox.showinfo('提示',message='数据加载失败')
|
|
|
|
messagebox.showinfo('提示',message='数据加载失败')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.image_url(self.current_data_index,0)
|
|
|
|
self.image_url(0)
|
|
|
|
|
|
|
|
|
|
|
|
def csv_is_empty(self):
|
|
|
|
def csv_is_empty(self):
|
|
|
|
with open('notes.csv','r',encoding='utf-8') as f2:
|
|
|
|
with open('notes.csv','r',encoding='utf-8') as f2:
|
|
|
@ -405,11 +508,57 @@ class Mainpage:
|
|
|
|
def func_collect(self):
|
|
|
|
def func_collect(self):
|
|
|
|
if self.max_data_count!=0:
|
|
|
|
if self.max_data_count!=0:
|
|
|
|
func_collec.collec(self.user, self.current_data_index)
|
|
|
|
func_collec.collec(self.user, self.current_data_index)
|
|
|
|
|
|
|
|
dic={}
|
|
|
|
|
|
|
|
with open(self.data_csv_file_path,'r',encoding='utf-8') as f:
|
|
|
|
|
|
|
|
reader = csv.reader(f)
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
for row in reader:
|
|
|
|
|
|
|
|
if i==self.current_data_index:
|
|
|
|
|
|
|
|
dic={
|
|
|
|
|
|
|
|
'文章ID':row[0],
|
|
|
|
|
|
|
|
'文章标题':row[1],
|
|
|
|
|
|
|
|
'图片资源':eval(row[3])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
i+=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(self.notes_csv_file_path,'r',encoding='utf-8') as f:
|
|
|
|
|
|
|
|
reader = csv.reader(f)
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
for row in reader:
|
|
|
|
|
|
|
|
if i==self.current_data_index:
|
|
|
|
|
|
|
|
dic['文章内容']=row[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open('collections/{}.csv'.format(self.user),'a+',encoding='utf-8',newline='') as f:
|
|
|
|
|
|
|
|
writer = csv.DictWriter(f, fieldnames=['文章ID','文章标题','图片资源','文章内容'])
|
|
|
|
|
|
|
|
writer.writerow(dic)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
messagebox.showinfo('提示','请先搜索')
|
|
|
|
messagebox.showinfo('提示','请先搜索')
|
|
|
|
|
|
|
|
|
|
|
|
def func_discollect(self):
|
|
|
|
def func_discollect(self):
|
|
|
|
dis_collect.dis_collec(self.user,self.current_data_index)
|
|
|
|
dis_collect.dis_collec(self.user,self.c_data_index)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
row_to_delete = self.c_data_index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 使用临时文件来存储修改后的内容
|
|
|
|
|
|
|
|
with open('collections/{}.csv'.format(self.user), newline='', encoding='utf-8') as csvfile, \
|
|
|
|
|
|
|
|
tempfile.NamedTemporaryFile(mode='w+t', newline='', encoding='utf-8', delete=False) as temp:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reader = csv.reader(csvfile)
|
|
|
|
|
|
|
|
writer = csv.writer(temp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 读取并写入除了要删除的行之外的所有行
|
|
|
|
|
|
|
|
for i, row in enumerate(reader):
|
|
|
|
|
|
|
|
if i != row_to_delete:
|
|
|
|
|
|
|
|
writer.writerow(row)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
os.remove('collections/{}.csv'.format(self.user))
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 将临时文件重命名为原始文件名
|
|
|
|
|
|
|
|
os.rename(temp.name, 'collections/{}.csv'.format(self.user))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|