|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import argparse |
| 3 | +import os.path |
| 4 | +from string import Template |
| 5 | + |
| 6 | +import leetcode |
| 7 | + |
| 8 | +PROBLEM_INFO_TEMPLATE = Template('''${problem_id} - ${title} |
| 9 | +${difficulty} - https://leetcode.com/problems/${slug}/" |
| 10 | +
|
| 11 | +${description} |
| 12 | +
|
| 13 | +${test_cases} |
| 14 | +''') |
| 15 | + |
| 16 | + |
| 17 | +def parse_args(): |
| 18 | + parser = argparse.ArgumentParser(description='Export LeetCode solutions') |
| 19 | + parser.add_argument('--username', type=str, required=False, help='LeetCode username') |
| 20 | + parser.add_argument('--password', type=str, required=False, help='LeetCode password') |
| 21 | + parser.add_argument('--folder', type=str, required=False, help='Output folder', default='out') |
| 22 | + parser.add_argument('--cookies', type=str, required=False, help='LeetCode cookies') |
| 23 | + |
| 24 | + return parser.parse_args() |
| 25 | + |
| 26 | + |
| 27 | +if __name__ == '__main__': |
| 28 | + args = parse_args() |
| 29 | + |
| 30 | + cookies = args.cookies |
| 31 | + |
| 32 | + print(leetcode.get_submissions(cookies)) |
| 33 | + # if not cookies or not leetcode.valid_cookies(cookies): |
| 34 | + # if not args.username: |
| 35 | + # print("Insert LeetCode username: ") |
| 36 | + # args.username = input() |
| 37 | + # |
| 38 | + # if not args.password: |
| 39 | + # print("Insert LeetCode username: ") |
| 40 | + # args.password = input() |
| 41 | + # |
| 42 | + # if not os.path.exists(args.folder): |
| 43 | + # os.mkdir(args.folder) |
| 44 | + # os.chdir(args.folder) |
| 45 | + # cookies = leetcode.get_cookies(args.username, args.password) |
| 46 | + # |
| 47 | + # solved_problems = leetcode.get_solved_problem_slugs(cookies) |
| 48 | + # |
| 49 | + # for slug in solved_problems: |
| 50 | + # if not os.path.exists(slug): |
| 51 | + # os.mkdir(slug) |
| 52 | + # os.chdir(slug) |
| 53 | + # problem_info = leetcode.get_problem(cookies, slug) |
| 54 | + # info_filename = f"{problem_info.slug}.txt" |
| 55 | + # if not os.path.exists(info_filename): |
| 56 | + # info_file = open(info_filename, 'w+') |
| 57 | + # info_file.write(PROBLEM_INFO_TEMPLATE.substitute(**problem_info.__dict__)) |
| 58 | + # info_file.close() |
| 59 | + # |
| 60 | + # submissions = leetcode.get_submissions(cookies, slug) |
| 61 | + # |
| 62 | + # for sub in submissions: |
| 63 | + # sub_filename = f"{sub.submission_date.strftime('%Y-%m-%d %H-%M-%S')} - {sub.status} - runtime: {sub.runtime} - memory: {sub.memory}.{sub.extension}" |
| 64 | + # if not os.path.exists(sub_filename): |
| 65 | + # sub_file = open(sub_filename, 'w+') |
| 66 | + # sub_file.write(sub.code) |
| 67 | + # sub_file.close() |
0 commit comments