-
Notifications
You must be signed in to change notification settings - Fork 0
/
problemParser.py
80 lines (66 loc) · 2.41 KB
/
problemParser.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
from parserLibs import *
import submissionParser
def parseProblems(curdate):
solved = submissionParser.parseSubmissions(curdate)
problems = {}
reloadProblems = True
if path.exists("parsedData\\problems.json"):
tmpProblems = {}
with open("parsedData\\problems.json","r") as read_file:
tmpProblems = json.load(read_file)
parseDate = tmpProblems["parseDate"]
print("Problems last parsed on " + parseDate + "\nReload Problems? (Y/N)")
inpChar = input()
if inpChar=='Y' or inpChar=='y':
reloadProblems = True
else:
problems = tmpProblems["data"]
reloadProblems = False
if reloadProblems:
print("Fetching problems...")
response = requests.get("https://codeforces.com/api/problemset.problems")
problems = json.loads(response.text)["result"]["problems"]
tmp = {}
tmp["parseDate"] = curdate
tmp["data"] = problems
with open("parsedData\\problems.json","w+") as write_file:
json.dump(tmp, write_file)
urlList = []
for problem in problems:
contestId = str(problem["contestId"])
if int(contestId)<915:
continue
if len(contestId)==0:
continue;
if "rating" not in problem:
continue
rating = problem["rating"]
if not (rating >= minRating and rating <= maxRating):
continue
tagsOK = True
if len(includedTags)>0:
if "tags" in problem:
for tag in includedTags:
if tag not in problem["tags"]:
tagsOK = False
else:
tagsOK = False
if len(excludedTags)>0:
if "tags" in problem:
for tag in excludedTags:
if tag in problem["tags"]:
tagsOK = False
if not tagsOK:
continue
index = str(problem["index"])
ProblemLink = "https://codeforces.com/problemset/problem/"+contestId+"/"+index
if ProblemLink in solved:
continue
tmp = []
tmp.append(ProblemLink)
tmp.append(problem["name"])
tmp.append(str(rating))
if "tags" in problem:
tmp.append(str(problem["tags"]))
urlList.append(tmp)
return urlList