-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcf_mashup_maker.py
86 lines (67 loc) · 1.98 KB
/
cf_mashup_maker.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
import codeforces_api as cf
import json, sys, os
from src.utils import *
import src.data_helper as data_helper
import src.config as config
import src.update as update
import src.mashup as mashup
cf_api = cf.CodeforcesApi()
config_name = sys.argv[1] if len(sys.argv) > 1 else "default"
try:
with open(f"data/{config_name}/solved.json", "r") as f:
json_object = json.load(f)
solved = set(json_object["problems"])
last_updated = json_object["last_updated"]
if os.path.exists(f"data/{config_name}/exclude.json"):
with open(f"data/{config_name}/exclude.json", "r") as f:
json_object = json.load(f)
solved = solved.union(set(json_object["list"]))
except:
solved = set()
last_updated = "Never"
def options():
print()
print("1. Make a new mashup.")
print(f"2. Update attempted problems list. (slow) [last updated: {last_updated}]")
print("3. Update config.")
print("4. Quit.")
print()
return int(input("Enter operation number: "))
def choose_option():
while True:
x = options()
line()
if x not in range(1, 5):
print("Please enter a valid number.")
continue
return x
def update_attempted():
global last_updated, solved
solved = update.update_solved_problems(cf_api)
last_updated = "Now"
print(f"Problems have been updated successfully. (total attempted: {len(solved)})")
line()
def make_mashup():
mashup_problems = mashup.pick_problems(cf_api, solved)
line()
print("Problems list:")
for i, problem in enumerate(mashup_problems):
print(i + 1, problem.name)
line()
def configure():
config.update_config()
line()
def first_run():
configure()
update_attempted()
data_helper.load(first_run, config_name)
while True:
x = choose_option()
if x == 1:
make_mashup()
elif x == 2:
update_attempted()
elif x == 3:
configure()
elif x == 4:
quit()