Last active
June 15, 2020 14:56
-
-
Save GuyAglionby/2ba789e59398d9a24c70f31cdd755573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import re | |
from datetime import datetime | |
from collections import defaultdict, OrderedDict | |
import yaml | |
re_session_extract = re.compile(r'\w+ (\w+) (\d+), (\d+) (\d+\w) ([\w\d\s:\-.,()]+-\d+) (\d+):(\d\d) UTC(.*)') | |
def extract_date(x): | |
month, date, year, session, session_name, hour, mins, timezone = re_session_extract.match(x).groups() | |
month_int = datetime.strptime(month, '%B').month | |
parsed_date = datetime(int(year), month_int, int(date), int(hour), int(mins)) | |
assert timezone == '+0' | |
return parsed_date, session | |
def main(): | |
track_filename = 'paper_tracks.xls' | |
track_details = pd.read_excel(track_filename) | |
track_details.rename(columns={'Line order': 'LineOrder'}, inplace=True) | |
track_details['Date1'], track_details['Session1'] = zip(*track_details['slot 1'].map(extract_date)) | |
track_details['Date2'], track_details['Session2'] = zip(*track_details['slot2'].map(extract_date)) | |
session_time_map = defaultdict(lambda: {'date': '', 'posters': []}) | |
id_session_map = {} | |
volume = '1' | |
for row in track_details.itertuples(): | |
session_time_map[row.Session1]['date'] = row.Date1 | |
session_time_map[row.Session1]['posters'].append({'id': volume + '.' + str(row.LineOrder), 'join_link': 'https://www.google.com/'}) | |
session_time_map[row.Session2]['date'] = row.Date2 | |
session_time_map[row.Session2]['posters'].append({'id': volume + '.' + str(row.LineOrder), 'join_link': 'https://www.google.com/'}) | |
# Sort everything | |
for session, session_info in session_time_map.items(): | |
session_info['posters'].sort(key=lambda x: int(x['id'].split('.')[1])) | |
dict_items = list(session_time_map.items()) | |
dict_items.sort(key=lambda x: x[1]['date']) | |
ordered_sessions = dict(dict_items) | |
for session, session_info in session_time_map.items(): | |
session_info['date'] = session_info['date'].strftime('%Y-%m-%d_%H:%M:%S') | |
with open('poster_schedule.yml', 'w') as f: | |
yaml.dump(ordered_sessions, f, default_flow_style=False, sort_keys=False) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment