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
=== modified file 'ibid/plugins/geography.py'
--- ibid/plugins/geography.py 2010-10-05 19:41:55 +0000
+++ ibid/plugins/geography.py 2011-06-26 22:46:41 +0000
@@ -125,7 +125,25 @@
125 'joburg': 'Johannesburg, South Africa',125 'joburg': 'Johannesburg, South Africa',
126 }126 }
127 places = DictOption('places', 'Alternate names for places', defaults)127 places = DictOption('places', 'Alternate names for places', defaults)
128 labels = ('temp', 'humidity', 'dew', 'wind', 'pressure', 'conditions', 'visibility', 'uv', 'clouds', 'ymin', 'ymax', 'ycool', 'sunrise', 'sunset', 'moonrise', 'moonset', 'moonphase', 'metar')128 labels = {'temperature': 'temp',
129 'humidity': 'humidity',
130 'dew point': 'dew',
131 'wind': 'wind',
132 'pressure': 'pressure',
133 'conditions': 'conditions',
134 'visibility': 'visibility',
135 'uv': 'uv',
136 'clouds': 'clouds',
137 "yesterday's minimum": 'ymin',
138 "yesterday's maximum": 'ymax',
139 "yesterday's cooling degree days": 'ycool',
140 'sunrise': 'sunrise',
141 'sunset': 'sunset',
142 'moon rise': 'moonrise',
143 'moon set': 'moonset',
144 'moon phase': 'moonphase',
145 'raw metar': 'metar',
146 }
129147
130 class WeatherException(Exception):148 class WeatherException(Exception):
131 pass149 pass
@@ -164,16 +182,16 @@
164182
165 def remote_weather(self, place):183 def remote_weather(self, place):
166 soup = self._get_page(place)184 soup = self._get_page(place)
167 tds = [x.table for x in soup.findAll('table') if x.table][0].findAll('td')185 tds = soup.findAll('td')
168186
169 # HACK: Some cities include a windchill row, but others don't187 values = {}
170 if len(tds) == 39:188 for index, td in enumerate(tds):
171 del tds[3]189 text = self._text(td).lower()
172 del tds[4]190 if text.startswith('updated:'):
173191 values['place'] = td.findAll('b')[1].string
174 values = {'place': tds[0].findAll('b')[1].string, 'time': tds[0].findAll('b')[0].string}192 values['time'] = td.findAll('b')[0].string
175 for index, td in enumerate(tds[2::2]):193 if text in self.labels:
176 values[self.labels[index]] = self._text(td)194 values[self.labels[text]] = self._text(tds[index+1])
177195
178 return values196 return values
179197

Subscribers

People subscribed via source and target branches

to all changes: