-
Notifications
You must be signed in to change notification settings - Fork 17
/
papercall_grabbing.py
125 lines (102 loc) · 4.21 KB
/
papercall_grabbing.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
115
116
117
118
119
120
121
122
123
124
125
"""
Functions to grab info from papercall.io
"""
import os
import time
import requests
token = 'your_papercall_token' # ,<-- fill this in
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
des_template = """
Title: {title}
URL: 2017/descriptions/{id}.html
save_as: 2017/descriptions/{id}.html
{description}
""".lstrip()
def get_submission_ids():
# Query all submission ids
all_ids = []
for state in ('submitted', 'accepted', 'rejected', 'waitlist'):
url = 'https://www.papercall.io/api/v1/submissions?_token=%s&per_page=999&state=%s'
all = requests.get(url % (token, state)).json()
all_ids.extend([x['id'] for x in all])
return all_ids
def get_reviewer_list():
""" Print out the names of all people who did reviews.
"""
# Collect submission ids
all_ids = get_submission_ids()
# Collect all reviewers
reviewers = set()
for id in all_ids:
url = 'https://www.papercall.io/api/v1/submissions/%s/ratings?_token=%s'
ratings = requests.get(url % (id, token)).json()
for rating in ratings:
reviewers.add(rating['user']['name'])
# Print a list
for reviewer in sorted(reviewers):
print(reviewer)
def get_talk_descriptions():
""" Get talk descriptions and store each in a markdown file.
"""
# Collect submission ids
all_ids = get_submission_ids()
# Collect descriptions
index = {}
for id in all_ids:
url = 'https://www.papercall.io/api/v1/submissions/%s?_token=%s'
submission = requests.get(url % (id, token)).json()
id = str(submission['id'])
title = submission['talk']['title']
page = des_template.format(description=submission['talk']['description'],
title=title, id=id)
fname = os.path.join(THIS_DIR, 'content', 'pages', '2017', 'descriptions', id + '.md')
with open(fname, 'wb') as f:
f.write(page.encode())
index[id] = title
time.sleep(0.1)
fname = os.path.join(THIS_DIR, 'content', 'pages', '2017', 'descriptions', 'index.md')
with open(fname, 'wb') as f:
for id in sorted(index):
line = id + ' - ' + index[id] + '\n'
f.write(line.encode())
def make_links_in_program():
""" Make the talk titles in the program link to description pages,
as far as we can, anyway. The rest should be done by hand by making use of
the descriptions.index.md.
Beware, this is ugly, and makes all kinds of assumptions about how the program
table is formatted, and it needs manual corrections, and it does not work after
it has applied the changes. We should probably just throw it away.
"""
# Build reverse index
rindex = {}
fname = os.path.join(THIS_DIR, 'content', 'pages', '2017', 'descriptions', 'index.md')
with open(fname, 'rb') as f:
for line in f.read().decode().splitlines():
if line.strip():
id, _, title = line.partition('-')
rindex[title.strip().lower()] = 'descriptions/' + id.strip() + '.html'
default_link = 'descriptions/oops.html'
# Add links
fname = os.path.join(THIS_DIR, 'content', 'pages', '2017', 'program.md')
text = open(fname, 'rb').read().decode()
lines = text.splitlines()
for i in range(len(lines)-1):
line = lines[i]
if line.lstrip().startswith("<td>") and not line.rstrip().endswith(">"):
if ' ' not in lines[i+1]:
title = line.lstrip()[4:]
id = rindex.get(title.strip().lower(), default_link)
lines[i] = " <td><a href='%s'>%s</a>" % (id, title)
if line.lstrip().startswith("<td>") and line.rstrip().endswith("</td>"):
if '<br>' in line and ' ' not in line:
title, _, rest = line.lstrip()[4:].partition('<br>')
id = rindex.get(title.strip().lower(), default_link)
lines[i] = " <td><a href='%s'>%s</a><br>%s" % (id, title, rest)
with open(fname, 'wb') as f:
text = '\n'.join(lines)
f.write(text.encode())
if __name__ == '__main__':
pass
# get_reviewer_list()
# get_talk_descriptions()
# make_links_in_program()