-
Notifications
You must be signed in to change notification settings - Fork 6
/
flug.py
93 lines (84 loc) · 2.79 KB
/
flug.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
import scraperwiki
import lxml.html
html = scraperwiki.scrape('http://www.isavia.is')
#print html
root = lxml.html.fromstring(html)
content = root.xpath ("//div [@class='content']/div[@class='item']")
class switch(object):
def __init__(self, value):
self.value = value
self.fall = False
def __iter__(self):
"""Return the match method once, then stop"""
yield self.match
raise StopIteration
def match(self, *args):
"""Indicate whether or not to enter a case suite"""
if self.fall or not args:
return True
elif self.value in args: # changed for v1.5, see below
self.fall = True
return True
else:
return False
for x in content:
record = {}
to = str(x.attrib['rel'])
for case in switch(to):
if case('RKV'):
to=' í Reykjavík (' + to + ')'
break
if case('AEY'):
to = ' á Akureyri (' + to + ')'
break
if case('KEF'):
to = ' í Keflavík (' + to + ')'
break
if case('EGS'):
to = ' á Egilsstöðum (' + to + ')'
break
if case('IFJ'):
to = ' á Ísafirði (' + to + ')'
break
if case('VEY'):
to = ' í Vestmannaeyjum (' + to + ')'
break
if case('HFN'):
to = ' á Hornafirði (' + to + ')'
break
if case('GRY'):
to = ' í Grímsey (' + to + ')'
break
if case('BIU'):
to = ' á Bíldudal (' + to + ')'
break
if case('VPN'):
to = ' á Vopnafirði (' + to + ')'
break
if case('THO'):
to = ' á Þórshöfn (' + to + ')'
break
if case('TEY'):
to = ' á Þingeyri (' + to + ')'
break
if case('GJR'):
to = ' á Gjögri (' + to + ')'
break
if case(): # default, could also just omit condition or 'if True'
to = to
record['to'] = to
#print x.text_content().encode('iso-8859-1') + ' --- ' + str(x.attrib)
record['from'] = x[0].text.encode('iso-8859-1')
record['flightcode'] = x[0][0].text.encode('iso-8859-1')
record['time'] = x[1].text.encode('iso-8859-1')
record['date'] = x[1][0].text.encode('iso-8859-1')
try:
record['comment'] = x[2].text#.encode('utf-8')
except AttributeError:
pass
try:
if 'Lent' in record['comment']:
print 'Klukkan ' + record['time'] + ' lenti vél ('+record['flightcode']+') frá ' + record['from'] + record['to'] + ' - http://info.flightmapper.net/flight/'+record['flightcode'][:2]+'_'+record['flightcode'][2:]
except TypeError:
pass
#print record