Esempio n. 1
0
    def __init__(self):
        # 读取配置
        with open("config.json", "r", encoding="utf-8") as f:
            config = json.loads(f.read())
            self.EMAIL = config['email']
            self.PASSWORD = config["password"]
            self.REFRESH = config['refresh']
            self.REPO_PATH = config["repo_path"]
            self.GIT_URL = config["git_url"]
            self.START_ID = config['download_start_id']
            self.END_ID = config["download_end_id"]
            self.RECENT_NUM = config['get_recent_submissions_nums']

        # 登陆的会话
        self.SESSION = login(self.EMAIL, self.PASSWORD)
        # 建立个人的数据库,仅第一次创建
        # 后面想刷新数据库,请将config中设置为True或者手动删除database
        self.USER_STATE = database_maker(self.SESSION, self.REFRESH)
            codedir = outdir + "/codes_auto/"
            codedir = Path(codedir)
            if not os.path.exists(codedir):
                os.makedirs(codedir)

            code_file = outdir + "/codes_auto/" + str(
                id) + "." + slug + lang_dic.get(lang, "")
            code_file = Path(code_file)  # 格式化path
            if os.path.exists(code_file): continue
            # 获取源码
            code = get_submission_by_id(session, submission_id)
            write_code_to_file(code, code_file, str(id), slug, lang)
            # print("Done.")
            time.sleep(0.1)  # 访问太快会报错,访问次数过多也会报错


if __name__ == "__main__":
    with open("config.json", "r", encoding="utf-8") as f:
        config = json.loads(f.read())
        EMAIL = config['email']
        PASSWORD = config["password"]
        REFRESH = config['refresh']
        OUTDIR = config["outdir"]
        GIT_URL = config["git_url"]
        START_ID = config['download_start_id']
        END_ID = config["download_end_id"]

    SESSION = login(EMAIL, PASSWORD)  # 登陆账号
    # 开始下载
    code_downloader(SESSION, START_ID, END_ID, OUTDIR)
Esempio n. 3
0
 def codes_download(self):
     self.SESSION = login(self.EMAIL, self.PASSWORD)
     code_downloader(self.SESSION, self.START_ID, self.END_ID,
                     self.REPO_PATH)
                    source = f"[{lang.title()}]({git_url}{id}.{slug}{lang_post})"
                else:
                    source = "To Do"
                line = f"|{id}|{title_cn}|{level}|{tags_cn}|{source}|\n"
                # print(line)
                md.write(line)


# 生成md文件
def readme_maker(user_state, git_url, outdir):
    print("README.md is building...")
    head_maker(user_state, outdir)
    grids_maker(git_url, outdir)
    print("README.md has been Done.")


if __name__ == "__main__":
    with open("config.json", "r", encoding="utf-8") as f:
        config = json.loads(f.read())
        EMAIL = config['email']
        PASSWORD = config["password"]
        REFRESH = config['refresh']
        OUTDIR = config["outdir"]
        GIT_URL = config["git_url"]
        START_ID = config['download_start_id']
        END_ID = config["download_end_id"]

    session = login(EMAIL, PASSWORD)
    user_state = get_problems(session,REFRESH)
    readme_maker(user_state,GIT_URL,OUTDIR)