-
Notifications
You must be signed in to change notification settings - Fork 0
/
getf2fhttp.py
108 lines (75 loc) · 3.71 KB
/
getf2fhttp.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
# getf2f.py
# 2015-04-02 Adrian Stephens
#
# Get the events for the date specified in settings into a list
from utils import f2fMergeRooms,getWanted,sortEvents
from events import Event
import requests
import lxml.html
def parseHTTP(settings, http):
""" Parse the specified HTTP string in a format unique to F2F into a list of Event objects """
from datetime import timedelta, datetime
dayToOffset = dict(sunday=0, monday=1, tuesday=2, wednesday=3, thursday=4, friday=5, saturday=6)
f2fTree = lxml.html.fromstring(http).getroottree()
schedule = f2fTree.findall('//div[@id="schedule"]')
assert (schedule),"Cannot find id schedule in F2F html"
days = schedule[0].findall('div')
events = []
for dayElement in days:
dayName = dayElement.get('id')
dayNumber = dayToOffset[dayName]
rows = dayElement.findall('table/tr')
for row in rows:
trackID = row.get('class')
if trackID.find('tr-track-') >= 0:
track = trackID[9:]
else:
track = None
continue
cols=[]
colElements = row.findall('td')
for colElement in colElements:
for t in colElement.itertext():
cols.append(t)
slotTime = cols[0]
times = slotTime.split("-")
try:
startTime = datetime.strptime(times[0], "%H:%M").time()
endTime = datetime.strptime(times[1], "%H:%M").time()
# These dateTimes are in the meeting timezone
startDateTime = settings.sessionDateTimes[dayNumber] + \
timedelta(hours=startTime.hour, minutes=startTime.minute)
endDateTime = settings.sessionDateTimes[dayNumber] + \
timedelta(hours=endTime.hour, minutes=endTime.minute)
breakout = cols[1]
shortBreakout = settings.getShortBreakout(breakout)
# Apply optional mapping to f2f description
if shortBreakout in settings.f2fToBreakout:
shortBreakout = settings.f2fToBreakout[shortBreakout]
wanted, inIMAT = getWanted(settings,track,shortBreakout,breakout)
if not wanted:
continue
room = cols[2].rstrip(", ") # Remove trailing fluff
event = Event(settings,startDateTime,endDateTime,shortBreakout,room,inIMAT,track)
events.append(event)
except:
print "Ignoring Invalid f2f http entry "
for c in cols:
print c
return events
def getf2fhttpEvents(settings):
"""
Return a list of f2f events from the current f2f attendee page
"""
if 'proxyIP' in settings.__dict__:
proxies = {'http':'http://{0}:{1}'.format(settings.proxyIP, str(settings.proxyPort)), 'https':'http://{0}:{1}'.format(settings.proxyIP, str(settings.proxyPort))}
else:
proxies = None
# Get f2f schedule
r = requests.get(settings.f2fScheduleURL, proxies=proxies)
assert (r.status_code == 200),"Cannot read f2f page: {0}".format(settings.f2fScheduleURL)
scheduleHTTP = r.text
# parse the http into f2f events
f2fEvents = parseHTTP(settings, scheduleHTTP)
assert (len(f2fEvents) > 0), "f2f page has no events"
return f2fMergeRooms(sortEvents(f2fEvents))