-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathleetcode-py-cli.py
114 lines (98 loc) · 2.72 KB
/
leetcode-py-cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import src.init as init
from src.service_async import *
from src.service_sync import *
from src.github import initGit
from dotenv import load_dotenv, set_key
import argparse
from tabulate import tabulate
load_dotenv()
parser = argparse.ArgumentParser(
description='''
''',
prog="leetcode-py-cli",
)
parser.add_argument(
"-a",
"--all",
help="Download all submissions from Leetcode",
action='store_true',
default=0,
)
parser.add_argument(
"-f",
"--force-update",
help="Forcefully update all solution.",
action='store_true',
default=0,
)
parser.add_argument(
"-s",
"--submission",
help="Download specific submission from Leetcode",
metavar='id'
)
parser.add_argument(
"-ls",
"--list-questions",
help="List solved questions with statistics",
action='store_true',
default=0,
)
parser.add_argument(
"-l",
"--login",
help="Login to Leetcode",
# metavar=('csrf', 'session'),
# nargs=2
action='store_true',
default=0,
)
parser.add_argument(
"-g",
"--github",
help="Push your code to github",
action='store_true',
default=0,
)
parser.add_argument("-v", "--version", action="version", version="%(prog)s 1.0")
args = parser.parse_args()
if args.all:
downloadAllSubmissions()
elif args.submission:
downloadSubmission(int(args.submission))
elif args.list_questions:
listSubmission()
ls = []
for i in init.jsonfile:
j = list(i.values())
ls.append([j[0], j[1], j[4], j[5], j[6], j[7]])
print(tabulate(sorted(ls, key= lambda x : x[0]), headers=["No.","Title", 'Submitted On', 'Memory', 'Time', 'Langauge'], tablefmt='fancy_grid'))
elif args.login:
# Add a check
if not check():
session = input("Enter LEETCODE_SESSION : ")
csrf = input("\nEnter csrftoken : ")
set_key('.env', 'LEETCODE_SESSION', session)
set_key('.env', 'LEETCODE_CSRFTOKEN', csrf)
else:
if not init.login_flag:
inp = input("You are already Logged in. Do you still want to change the details.[Y/n] : ")
if inp.lower() == 'y':
session = input("Enter LEETCODE_SESSION : ")
csrf = input("\nEnter csrftoken : ")
set_key('.env', 'LEETCODE_SESSION', session)
set_key('.env', 'LEETCODE_CSRFTOKEN', csrf)
elif args.github:
# Add a check
if not checkGithubToken():
git = input('Enter Github token : ')
set_key('.env', 'GITHUB_TOKEN', git)
os.environ["GITHUB_TOKEN"] = git
load_dotenv()
downloadAllSubmissions()
initGit()
elif args.force_update:
init.availableSubmissions = []
downloadAllSubmissions()
else:
parser.print_help()