Filled or still accepting? What's the status...
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
from pyquery.pyquery import PyQuery
from datetime import datetime, timedelta, time
import re
def parse_time(hour_time):
try:
return datetime.strptime(hour_time, '%I:%M%p').time()
except ValueError:
return datetime.strptime(hour_time, '%I%p').time()
def parse_fanime_sessions(unix_time):
url = 'http://m.fanime.com/index.php?grid=%d' % unix_time
dom = PyQuery(url)
event_datetime = datetime.fromtimestamp(unix_time)
date = event_datetime.date()
time_start = event_datetime.time()
time_end = (event_datetime + timedelta(hours = 1)).time()
row_pattern = r'table.grid tr'
col_pattern = r'td'
rows = dom(row_pattern)
schedule = []
MIDNIGHT_TIME = time(0, 0, 0)
for row in rows:
py_row = PyQuery(row)
cols = py_row(col_pattern)
for index in range(len(cols)):
td = PyQuery(cols[index])
css_class = td.attr.class_
# clean_text = td.text().replace(' ', ' ')
clean_room_and_track = td.text().replace(u'\xa0', ' ')
room_and_track_re = re.search('([^\(]+)\s\(([^\)]+)', clean_room_and_track)
if css_class == 'track':
schedule += [{
'date': date,
'title': None,
'room': room_and_track_re.group(2),
'track': room_and_track_re.group(1),
'time_start': time_start,
'time_end': time_end,
}]
elif css_class in ['skip', 'partial']:
#===============================================================================
# Case
# continues from 11:30am, begins at 12:30pm => start_time: 11:30am
# ends at 12:30pm, runs until 2:30pm => end_time: 12:30pm
# [all day] => start_time = end_time = 0:00am
#===============================================================================
event = schedule[-1]
if clean_room_and_track == '[all day]':
event['time_start'] = MIDNIGHT_TIME
event['time_end'] = MIDNIGHT_TIME
elif 'continues from' in clean_room_and_track or 'begins at' in clean_room_and_track:
text_parts = clean_room_and_track.split()
event['time_start'] = parse_time(text_parts[-1])
elif 'ends at' in clean_room_and_track or 'runs until' in clean_room_and_track:
text_parts = clean_room_and_track.split()
event['time_end'] = parse_time(text_parts[-1])
else:
raise Exception("UNHANDLED CASE")
else:
schedule[-1]['title'] = clean_room_and_track
return schedule
def get_schedule(start_time, end_time):
current_unix_time = start_time
schedule = []
while current_unix_time < end_time:
sessions = parse_fanime_sessions(current_unix_time)
# for item in schedule:
# pprint(item, indent=4)
schedule += sessions
current_unix_time += (60 * 60)
return schedule
def print_guidebook_csv(schedule, filename = None):
if filename:
file_handle = open(filename, 'w')
else:
file_handle = None
CSV_HEADER = 'Session Title,Date,Time Start,Time End,Room/Location,Schedule Track (Optional),Description (Optional)'
if file_handle:
file_handle.write("{}\n".format(CSV_HEADER))
else:
print CSV_HEADER
for session in schedule:
# print session
session['title'] = session['title'].replace('"', '')
session['track'] = session['track'].replace('Tabletop Gaming Tournaments', 'Tabletop Gaming')
csv_line = '"%(title)s", %(date)s, %(time_start)s, %(time_end)s, %(room)s, %(track)s, ""' % session
if file_handle:
file_handle.write("{}\n".format(csv_line))
else:
print csv_line
if file_handle:
file_handle.close()
if __name__ == '__main__':
#===========================================================================
# Fanime 2013 (1369350000 to 1369695600) ( Thursday 5pm - Monday 4pm)
# 1369688400 - Monday, 2pm
# 1369692000 - Monday, 3pm
#===========================================================================
# Thursdaay 6pm - Midnight
ONE_HOUR = 60 * 60
SIX_HOUR = ONE_HOUR * 6
schedule = []
# THURSDAY
THURSDAY_6PM = 1369357200
THURSDAY_11PM = THURSDAY_6PM + SIX_HOUR - ONE_HOUR
print '%d - %d ' % (THURSDAY_6PM, THURSDAY_11PM)
schedule += get_schedule(THURSDAY_6PM, THURSDAY_11PM)
# FRIDAY
FRIDAY_MIDNIGHT = THURSDAY_11PM + ONE_HOUR
FRIDAY_11PM = FRIDAY_MIDNIGHT + (SIX_HOUR * 4) - ONE_HOUR
print '%d - %d ' % (FRIDAY_MIDNIGHT, FRIDAY_11PM)
schedule += get_schedule(FRIDAY_MIDNIGHT, FRIDAY_11PM)
# SATURDAY
SATURDAY_MIDNIGHT = FRIDAY_11PM + ONE_HOUR
SATURDAY_11PM = SATURDAY_MIDNIGHT + (SIX_HOUR * 4) - ONE_HOUR
print '%d - %d ' % (SATURDAY_MIDNIGHT, SATURDAY_11PM)
schedule += get_schedule(SATURDAY_MIDNIGHT, SATURDAY_11PM)
# SUNDAY
SUNDAY_MIDNIGHT = SATURDAY_11PM + ONE_HOUR
SUNDAY_11PM = SUNDAY_MIDNIGHT + (SIX_HOUR * 4) - ONE_HOUR
print '%d - %d ' % (SUNDAY_MIDNIGHT, SUNDAY_11PM)
schedule += get_schedule(SUNDAY_MIDNIGHT, SUNDAY_11PM)
# MONDAY
MONDAY_MIDNIGHT = SUNDAY_11PM + ONE_HOUR
MONDAY_3PM = 1369692000
print '%d - %d ' % (MONDAY_MIDNIGHT, MONDAY_3PM)
schedule += get_schedule(MONDAY_MIDNIGHT, MONDAY_3PM)
filename = 'Fanime_2013.csv'
print_guidebook_csv(schedule, filename)
Quote from: Jeimizu on May 20, 2013, 07:57:34 AMIt's the matter of convenience. Creating schedule with google calendar would require much more time for an indvidual than you just click an icon in the app. Browsing through pdf is cumbersome for me.
It works on my phone, and it's not worth the download. All the info could be in a pdf, and that would be a lot less than the 18.75 mb this takes up on my phone.
If people want to do a schedule, us Google Calender. It's free and you can use it collaboratively.
Quote from: ewu on May 19, 2013, 09:58:11 PMI took your comment into consideration and looked for alternative. I found bloodhound and made a guide for Clockwork Alchemy 2013 (since their schedule is online).
guidebook charge cons money....that's money away from programming, like a few thousand....it was a balance...
Page created in 0.264 seconds with 17 queries.