Merge lp:~stefanor/ibid/wund-716141 into lp:ibid

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 1032
Merged at revision: 1035
Proposed branch: lp:~stefanor/ibid/wund-716141
Merge into: lp:ibid
Diff against target: 56 lines (+29/-11)
1 file modified
ibid/plugins/geography.py (+29/-11)
To merge this branch: bzr merge lp:~stefanor/ibid/wund-716141
Reviewer Review Type Date Requested Status
Max Rabkin Approve
Review via email: mp+65921@code.launchpad.net

Commit message

Don't expect the WUND tables to be in any particular order

To post a comment you must log in.
Revision history for this message
Max Rabkin (max-rabkin) wrote :

I'd like some tests so that we catch other scraping errors.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/geography.py'
2--- ibid/plugins/geography.py 2010-10-05 19:41:55 +0000
3+++ ibid/plugins/geography.py 2011-06-26 22:46:41 +0000
4@@ -125,7 +125,25 @@
5 'joburg': 'Johannesburg, South Africa',
6 }
7 places = DictOption('places', 'Alternate names for places', defaults)
8- labels = ('temp', 'humidity', 'dew', 'wind', 'pressure', 'conditions', 'visibility', 'uv', 'clouds', 'ymin', 'ymax', 'ycool', 'sunrise', 'sunset', 'moonrise', 'moonset', 'moonphase', 'metar')
9+ labels = {'temperature': 'temp',
10+ 'humidity': 'humidity',
11+ 'dew point': 'dew',
12+ 'wind': 'wind',
13+ 'pressure': 'pressure',
14+ 'conditions': 'conditions',
15+ 'visibility': 'visibility',
16+ 'uv': 'uv',
17+ 'clouds': 'clouds',
18+ "yesterday's minimum": 'ymin',
19+ "yesterday's maximum": 'ymax',
20+ "yesterday's cooling degree days": 'ycool',
21+ 'sunrise': 'sunrise',
22+ 'sunset': 'sunset',
23+ 'moon rise': 'moonrise',
24+ 'moon set': 'moonset',
25+ 'moon phase': 'moonphase',
26+ 'raw metar': 'metar',
27+ }
28
29 class WeatherException(Exception):
30 pass
31@@ -164,16 +182,16 @@
32
33 def remote_weather(self, place):
34 soup = self._get_page(place)
35- tds = [x.table for x in soup.findAll('table') if x.table][0].findAll('td')
36-
37- # HACK: Some cities include a windchill row, but others don't
38- if len(tds) == 39:
39- del tds[3]
40- del tds[4]
41-
42- values = {'place': tds[0].findAll('b')[1].string, 'time': tds[0].findAll('b')[0].string}
43- for index, td in enumerate(tds[2::2]):
44- values[self.labels[index]] = self._text(td)
45+ tds = soup.findAll('td')
46+
47+ values = {}
48+ for index, td in enumerate(tds):
49+ text = self._text(td).lower()
50+ if text.startswith('updated:'):
51+ values['place'] = td.findAll('b')[1].string
52+ values['time'] = td.findAll('b')[0].string
53+ if text in self.labels:
54+ values[self.labels[text]] = self._text(tds[index+1])
55
56 return values
57

Subscribers

People subscribed via source and target branches

to all changes: