forked from cookiedoth/cf-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.py
29 lines (24 loc) · 776 Bytes
/
read.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
import csv
import requests
print('Getting correct tags')
problems = requests.get("https://codeforces.com/api/problemset.problems").json()
problem_to_tags = {}
for problem in problems['result']['problems']:
problem_to_tags[problem['name']] = ','.join(problem.get('tags', []))
headers = ['name', 'legend', 'input', 'output', 'note', 'rating', 'tags']
rows = [headers]
print('Reading broken csv')
csvfile = open('cf.csv', newline='')
reader = csv.DictReader(csvfile)
for problem in reader:
if problem['name'] == 'name':
continue
problem['tags'] = problem_to_tags[problem['name']]
rows.append([problem[key] for key in headers])
csvfile.close()
print('Writing new csv')
f = open('cf_new.csv', 'w')
writer = csv.writer(f)
for row in rows:
writer.writerow(row)
f.close()