Skip to content

Commit

Permalink
chore(scripts): move .py scripts to a folder
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavio committed Nov 23, 2019
1 parent 5887275 commit b3968ac
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions papercall_grabbing.py → scripts/papercall_grabbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

token = 'your_papercall_token' # ,<-- fill this in

THIS_DIR = os.path.abspath(os.path.dirname(__file__))
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

des_template = """
Title: {title}
Expand All @@ -34,15 +34,15 @@ def get_reviewer_list():
"""
# 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)
Expand All @@ -53,7 +53,7 @@ def get_talk_descriptions():
"""
# Collect submission ids
all_ids = get_submission_ids()

# Collect descriptions
index = {}
for id in all_ids:
Expand All @@ -63,13 +63,13 @@ def get_talk_descriptions():
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')
fname = os.path.join(ROOT_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')

fname = os.path.join(ROOT_DIR, 'content', 'pages', '2017', 'descriptions', 'index.md')
with open(fname, 'wb') as f:
for id in sorted(index):
line = id + ' - ' + index[id] + '\n'
Expand All @@ -80,24 +80,24 @@ 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')
fname = os.path.join(ROOT_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')
fname = os.path.join(ROOT_DIR, 'content', 'pages', '2017', 'program.md')
text = open(fname, 'rb').read().decode()
lines = text.splitlines()
for i in range(len(lines)-1):
Expand All @@ -112,7 +112,7 @@ def make_links_in_program():
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())
Expand Down

0 comments on commit b3968ac

Please sign in to comment.