-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_papers_cache.py
47 lines (36 loc) · 1.22 KB
/
update_papers_cache.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
import json
import os
import requests
from tqdm import tqdm
PROGRAM_FILE = os.path.join('data', 'program.json')
PAPERS_CACHE_FILE = os.path.join('data', 'papers_cached.json')
def load_papers_ids():
paper_ids = []
with open(PROGRAM_FILE) as json_file:
data = json.load(json_file)
for session in data['sessions']:
for lecture in session.get('lectures', []):
if 'paperId' in lecture:
paper_ids.append(lecture['paperId'])
return paper_ids
def load_papers_data(paper_ids):
papers = []
for paper_id in tqdm(paper_ids):
if paper_id != "vid":
url = f'https://uconfy.com/papers/api/papers/{paper_id}'
response = requests.get(url)
papers.append(response.json())
return papers
def write_papers(papers):
with open(PAPERS_CACHE_FILE, 'w') as json_file:
json.dump(papers, json_file)
if __name__ == '__main__':
print('* Loading papers IDs')
ids = load_papers_ids()
print(f' -> {len(ids)} IDs loaded')
print('* Loading papers data')
data = load_papers_data(ids)
print(f' -> {len(data)} papers loaded')
print('* Writing papers cache')
write_papers(data)
print('= Finished')