这次没文案,用python给ccmtv高效学习工具写了个gui,加入了补签功能。
尝试着用python标准库tkinter为签到工具增加了图形化交互功能,虽然用tkinter写gui不美观,但它兼容性和体积都很好啊。
由于要打包成exe文件,给gui加图标不方便,硬编码保存图片还要导入非标准库增大文件体积。不弄了,不弄了。。。
2020.5.22修改了header参数,文末打包好的软件未进行修改。请自行取用源代码执行或打包。
放 代 码 🐎
import tkinter as tk
from tkinter import ttk
import requests, json
from time import sleep
from os import path
headers = {
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "no-cache",
"connection": "keep-alive",
"host": "yun.ccmtv.cn",
"pragma": "no-cache",
"User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"}
loginurl = "http://www.ccmtv.cn/upload_files/new_upload_files/ccmtvtp/Loginreg/Login/loginCheck.html"
taskurl = "http://www.ccmtv.cn/upload_files/new_upload_files/ccmtvtp/Member/Yktask/noListAjax.html"
oldtaskurl = "http://www.ccmtv.cn/upload_files/new_upload_files/ccmtvtp/Member/Yktask/yesListAjax.html"
signurl = "http://yun.ccmtv.cn/Video/signInData.html"
logouturl = "http://www.ccmtv.cn/upload_files/new_upload_files/ccmtvtp/Member/Index/loginout.html"
videologurl = "http://yun.ccmtv.cn/Video/addVideoLog"
win = tk.Tk()
win.title("签到工具")
win.resizable(0, 0)
username = tk.StringVar()
passwd = tk.StringVar()
def loadconfig():
global username, passwd
if path.exists("ccmtv.ini"):
with open("ccmtv.ini", "r") as f:
i = json.load(f)
try:
username.set(i["username"])
passwd.set(i["passwd"])
except:
username.set("")
passwd.set("")
def dologin():
if username.get() == "" or passwd.get() == "":
info.configure(text="用户名或密码不能为空")
return ()
global s
with open("ccmtv.ini", "w") as f:
json.dump({"username": username.get(), "passwd": passwd.get()}, f)
s = requests.Session()
s.headers = headers
s.cookies = requests.cookies.RequestsCookieJar()
login = s.post(loginurl, {"username": username.get(), "password": passwd.get()})
if login.status_code == 200 and json.loads(login.text) == "http://www.ccmtv.cn":
print(json.loads(login.text))
logsuccess()
else:
info.configure(text="登陆失败")
s.close()
def logsuccess():
labelframe.configure(text="已登录")
info.configure(text="登录成功")
framelogin.grid_remove()
framelogged.grid(column=0, row=0)
def signreq(c):
for tid, t in c.items():
for aid in t[1]:
for n in range(t[0]):
yield ({"aid": aid, "tid": tid, "sign_num": n})
def videologreq(c):
for tid, t in c.items():
for aid in t[1]:
yield ({"aid": aid})
def gettask():
task = s.get(taskurl)
try:
tasklist = json.loads(task.text)
except:
info.configure(text="获取任务列表失败")
return (-1)
c = {i["tid"]: (json.loads(i["sign_num"]), json.loads(i["taskitem"])["1"]) for i in tasklist["list"] if
i["rate_of_progress"] < 100}
if not bool(c):
return (1)
return (c)
def dosign():
c = gettask()
if isinstance(c, int):
if c == 1:
info.configure(text="无需签到-,-")
return ()
elif c == -1:
return ()
else:
info.configure(text="正在签到...")
for req in signreq(c):
s.post(signurl, req)
sleep(0.2)
for req in videologreq(c):
b = s.post(videologurl, req)
sleep(0.2)
check = gettask()
if isinstance(check, int):
if check == 1:
info.configure(text="全部都帮你签好了")
return ()
elif check == -1:
return ()
else:
info.configure(text="签到失败=_=")
return ()
def dooldsign():
oldtask = s.post(oldtaskurl, {"limit": 999})
oldtasklist = json.loads(oldtask.text)
oldc = {i["tid"]: (json.loads(i["sign_num"]), json.loads(i["taskitem"])["1"]) for i in oldtasklist["list"] if
i["rate_of_progress"] < 100}
if not bool(oldc):
info.configure(text="无需补签~")
else:
info.configure(text="正在补签...")
for req in signreq(oldc):
s.post(signurl, req)
sleep(0.2)
for req in videologreq(oldc):
b = s.post(videologurl, req)
sleep(0.2)
info.configure(text="补签完事儿了...")
def logout():
s.get(logouturl)
s.close()
def dologout():
labelframe.configure(text="未登录")
info.configure(text="已注销")
framelogin.grid(column=0, row=0)
framelogged.grid_remove()
logout()
frame1 = ttk.Frame(win)
frame1.grid(column=0, row=0, padx=5, pady=5)
labelframe = ttk.LabelFrame(frame1, text="未登录")
labelframe.grid(column=0, row=0)
framelogin = ttk.Frame(labelframe)
framelogged = ttk.Frame(labelframe)
ttk.Label(framelogin, text="用户名:", width=10).grid(column=0, row=0, sticky="W", padx=10, pady=5)
ttk.Label(framelogin, text="密 码:", width=10).grid(column=0, row=1, sticky="W", padx=10, pady=5)
ttk.Entry(framelogin, width=13, textvariable=username).grid(column=1, row=0, sticky="E", padx=10, pady=5)
ttk.Entry(framelogin, width=13, textvariable=passwd, show="*").grid(column=1, row=1, sticky="E", padx=10, pady=5)
ttk.Button(framelogin, text="登录", width=10, command=dologin).grid(column=1, row=2, sticky="E", padx=10, pady=5)
ttk.Button(framelogged, text="签到", width=7, command=dosign).grid(column=1, row=0, sticky="W", padx=6, pady=10)
ttk.Button(framelogged, text="补签", width=7, command=dooldsign).grid(column=2, row=0, padx=6, pady=10)
ttk.Button(framelogged, text="注销", width=7, command=dologout).grid(column=3, row=0, sticky="E", padx=6, pady=10)
framelogin.grid(column=0, row=0)
frame2 = ttk.Frame(win)
frame2.grid(column=0, row=1, padx=5, pady=10)
infoframe = ttk.LabelFrame(frame2, text=" 状态 ")
infoframe.grid(column=0, row=0)
info = ttk.Label(infoframe, text="高效学习 快乐成长", width=27, anchor="center")
info.grid(column=0, row=0, padx=10, pady=5)
loadconfig()
def exitcallback():
try:
logout()
finally:
win.destroy()
win.protocol('WM_DELETE_WINDOW', exitcallback)
win.mainloop()
Licensed under a CC BY-NC-ND 4.0 International License.
厉害厉害
可以尝试上传GitHub,做成脚本然后插件运行,我很爱用这种
就一院同学能用上,没必要github,下载还怪慢的