进程表自动机

由于luogu更新了,所以目前不可用

赞颂 xiezheyuan 巨佬,他发明了“进程表自动机“,为广大 OIer 作出了巨大贡献!

下面是源代码:

import requests, re, urllib, json, bs4
import time as tim

账号名 = ""
账户ID = 
密码 = ""

headers = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70",
    "referer" : "https://www.luogu.com.cn/"
}

session = requests.session()
main = session.get("http://www.luogu.com.cn/", headers=headers).text
headers["x-csrf-token"] = bs4.BeautifulSoup(main, "html.parser").select_one("meta[name=\"csrf-token\"]").attrs["content"]

data = session.get("https://www.luogu.com.cn/auth/login", headers=headers).text

def get_data(text):
    return json.loads(urllib.parse.unquote(re.findall(r"JSON.parse\(decodeURIComponent\(\".*\"\)\)", text)[0].split("\"")[1].split("\"")[0]))

data = get_data(data)

captcha = session.get("https://www.luogu.com.cn/api/verify/captcha?_t=" + str(
    data["currentTime"]
), headers=headers).content

with open("captcha.jpg", "wb") as f:
    f.write(captcha)

captcha = input("输入验证码:")

syncToken = session.post("https://www.luogu.com.cn/api/auth/userPassLogin", headers=headers, json={
    "username" : 账号名,
    "password" : 密码,
    "captcha" : captcha
}).json()
print(syncToken)

syncToken=syncToken["syncToken"]

session.post("https://www.luogu.org/api/auth/syncLogin", headers, json = {"syncToken" : syncToken})

page = 1
end = True

截止日期 = "2023-01-08"
endtime = tim.mktime(tim.strptime(截止日期, "%Y-%m-%d"))

problems = {}

while end:
    print("https://www.luogu.com.cn/record/list?user=%d&page=%d&status=12" % (账户ID, page))
    data = get_data(session.get("https://www.luogu.com.cn/record/list?user=%d&page=%d&status=12" % (账户ID, page), headers=headers).text)["currentData"]
    record = data["records"]["result"]
    if len(record) == 0:
        break
    for i in record:
        time = i["submitTime"]
        if time < endtime:
            end = False
            break
        date = tim.strftime("%Y 年 %m 月 %d 日", tim.localtime(time))
        if problems.get(date) is None:
            problems[date] = []
        problems[date].append({
            "name" : i["problem"]["pid"] + " " + i["problem"]["title"],
            "difficulty" : i["problem"]["difficulty"],
            "link" : "https://www.luogu.com.cn/problem/%s" % i["problem"]["pid"]
        })

    page += 1

difficulties = ["暂无评定", "入门", "普及-", "普及/提高-", "普及+/提高", "提高+/省选-", "省选/NOI-", "NOI/NOI+/CTSC"]

maps = dict()

with open("进程表.md", "w", encoding="utf-8") as f:
    for i in problems:
        pro = []
        for j in problems[i]:
            if maps.get(j["name"]) is None:
                pro.append(j)
                maps[j["name"]]=114514
        f.write("\n\n## %s\n\n" % i)
        if len(pro) == 0:
            continue
        f.write("| 题目名 | 难度 | 备注 |\n| :--: | :--: | :--: |\n")
        for j in pro:
            f.write("| [%s](%s) | %s |  |\n" % (j["name"], j["link"], difficulties[j["difficulty"]]))

保存到桌面并运行,运行中会下载一个图片验证码在桌面,输入验证码,然后程序会生成一个md文件(格式为mardown),打开复制到云剪切板即可

posted @ 2023-03-07 13:03  ccrui  阅读(13)  评论(0)    收藏  举报