def get_lcof_questions(): """获取剑指Offer题目""" resp = fetch(url=lcof_problems_url, headers=async_headers) if resp is None: return None res = resp.json() questions = res['stat_status_pairs'] for question in questions: fe_qid = question['stat']['frontend_question_id'] qno = fe_qid.replace('面试题', '').strip() title = question['stat']['question__title'].replace(' LCOF', '').strip() link = problems_url + question['stat']['question__title_slug'] git_link = '/lcof/{}/README.md'.format(quote(fe_qid + '. ' + title)) col1 = '[{}]({})'.format(qno, link) col2 = '[{}]({})'.format(title, git_link) col3 = difficulties.get(str(question['difficulty']['level'])) yield [col1, col2, col3]
def get_all_questions(): """获取所有题目""" cn_res = get_cn_questions() resp = fetch(url=all_problems_url, headers=async_headers) if resp is None: return res = resp.json() questions = res['stat_status_pairs'] for question in questions: qid = str(question['stat']['question_id']).zfill(4) title = question['stat']['question__title'] link = problems_url + question['stat']['question__title_slug'] git_link = '/solution/{}/README.md'.format(qid + '.' + quote(title)) cn_title = cn_res.get(qid) or title col1 = '[{}]({})'.format(qid, link) col2 = '[{}]({})'.format(cn_title, git_link) col3 = difficulties.get(str(question['difficulty']['level'])) yield [col1, col2, col3]