|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | import argparse |
3 | | -import getpass |
4 | 3 | import logging |
5 | 4 | import os |
6 | 5 | from string import Template |
|
18 | 17 |
|
19 | 18 | def parse_args(): |
20 | 19 | parser = argparse.ArgumentParser(description='Export LeetCode solutions') |
21 | | - parser.add_argument('--username', type=str, help='Set LeetCode username') |
22 | | - parser.add_argument('--password', type=str, help='Set LeetCode password') |
23 | 20 | parser.add_argument('--cookies', type=str, help='Set LeetCode cookies') |
24 | 21 | parser.add_argument('--folder', type=str, default='.', help='Output folder') |
25 | 22 | parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Enable verbose logging details') |
@@ -58,35 +55,16 @@ def main(): |
58 | 55 | submission_template = Template(args.submission_filename) |
59 | 56 |
|
60 | 57 | leetcode = LeetCode() |
61 | | - username = '' |
62 | | - password = '' |
63 | | - cookies = '' |
64 | | - |
65 | | - # Login into leetcode |
66 | | - if (not args.username or not args.password) and not args.cookies: |
67 | | - choice = input("How do you want to login?\n 1 - Username and Password\n 2 - Cookies\n") |
68 | | - while choice != '1' and choice != '2': |
69 | | - print("Choice not valid, input 1 or 2") |
70 | | - choice = input("How do you want to login?\n 1 - Username and Password\n 2 - Cookies\n") |
71 | | - |
72 | | - if choice == '1': |
73 | | - username = input("Insert LeetCode username: ") |
74 | | - password = getpass.getpass(prompt="Insert LeetCode password: ") |
75 | | - else: |
76 | | - cookies = input("Insert LeetCode cookies: ") |
77 | | - else: |
78 | | - username = args.username |
79 | | - password = args.password |
80 | | - cookies = args.cookies |
| 58 | + cookies = args.cookies |
| 59 | + |
| 60 | + if not cookies: |
| 61 | + cookies = input("Insert LeetCode cookies: ") |
81 | 62 |
|
82 | | - if username and password and not leetcode.log_in(args.username, args.password): |
| 63 | + if not leetcode.set_cookies(cookies): |
83 | 64 | print( |
84 | | - "Login not successful! You might have entered the wrong username/password or you need to complete the reCAPTCHA. If you need to complete the reCAPTCHA, log in with the cookies instead. Check the log for more information.") |
| 65 | + "Cookies not valid. Copy them from the Network tab of your browser by clicking on any leetcode.com request and going in Request Headers > cookie.") |
85 | 66 | exit(1) |
86 | 67 |
|
87 | | - if cookies: |
88 | | - leetcode.set_cookies(cookies) |
89 | | - |
90 | 68 | # Create output folder if it doesn't already exist |
91 | 69 | if not os.path.exists(args.folder): |
92 | 70 | os.mkdir(args.folder) |
|
0 commit comments