Merge lp:~davidc3/unity-scope-openweathermap/less-random-previews into lp:unity-scope-openweathermap

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 25
Merged at revision: 23
Proposed branch: lp:~davidc3/unity-scope-openweathermap/less-random-previews
Merge into: lp:unity-scope-openweathermap
Diff against target: 115 lines (+31/-22)
2 files modified
data/openweathermap.scope.in (+1/-1)
src/unity_openweathermap_daemon.py (+30/-21)
To merge this branch: bzr merge lp:~davidc3/unity-scope-openweathermap/less-random-previews
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+159324@code.launchpad.net

Commit message

Tag results with a random int to pick a Flickr photo for each result instead of doing it for each preview generation

Description of the change

Tag results with a random int to pick a Flickr photo for each result instead of doing it for each preview generation

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
24. By David Callé

Use a metadata field for the photo hint

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
25. By David Callé

Don't pass variants during resultset creation

Revision history for this message
David Callé (davidc3) wrote :

To test the last rev, you need libunity-7.0 rev > 361

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
David Callé (davidc3) wrote :

^ Obviously, he doesn't have it :)

Revision history for this message
Michal Hruby (mhr3) wrote :

+1 latest libunity should be in the PPA, so it should pass fine.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/openweathermap.scope.in'
--- data/openweathermap.scope.in 2013-03-22 18:18:40 +0000
+++ data/openweathermap.scope.in 2013-04-17 17:02:34 +0000
@@ -4,7 +4,7 @@
4Icon=4Icon=
5_Keywords=openweathermap;weather;sky;forecast;5_Keywords=openweathermap;weather;sky;forecast;
6RequiredMetadata=6RequiredMetadata=
7OptionalMetadata=min_temp[s];max_temp[s];pressure[s];humidity[s];wind_speed[s];wind_direction[s];latitude[s];longitude[s];7OptionalMetadata=min_temp[s];max_temp[s];pressure[s];humidity[s];wind_speed[s];wind_direction[s];latitude[s];longitude[s];photo_hint[i];
8Loader=/usr/share/unity-scopes/openweathermap/unity_openweathermap_daemon.py8Loader=/usr/share/unity-scopes/openweathermap/unity_openweathermap_daemon.py
9RemoteContent=true9RemoteContent=true
10Type=info10Type=info
1111
=== modified file 'src/unity_openweathermap_daemon.py'
--- src/unity_openweathermap_daemon.py 2013-03-26 17:54:44 +0000
+++ src/unity_openweathermap_daemon.py 2013-04-17 17:02:34 +0000
@@ -72,7 +72,10 @@
72m8 = {'id' :'longitude',72m8 = {'id' :'longitude',
73 'type' :'s',73 'type' :'s',
74 'field':Unity.SchemaFieldType.OPTIONAL}74 'field':Unity.SchemaFieldType.OPTIONAL}
75EXTRA_METADATA = [m1, m2, m3, m4, m5, m6, m7, m8]75m9 = {'id' :'photo_hint',
76 'type' :'i',
77 'field':Unity.SchemaFieldType.OPTIONAL}
78EXTRA_METADATA = [m1, m2, m3, m4, m5, m6, m7, m8, m9]
7679
77def weather_search(query, s_type):80def weather_search(query, s_type):
78 print (query)81 print (query)
@@ -167,18 +170,20 @@
167 return results170 return results
168 if not uri or not city_id:171 if not uri or not city_id:
169 return results172 return results
173 photo_hint = randrange(20)
170 results.append({'uri':uri,174 results.append({'uri':uri,
171 'icon':icon,175 'icon':icon,
172 'title':title,176 'title':title,
173 'comment':description,177 'comment':description,
174 'min_temp':GLib.Variant('s', min_temp),178 'min_temp':min_temp,
175 'max_temp':GLib.Variant('s', max_temp),179 'max_temp':max_temp,
176 'pressure':GLib.Variant('s', str(pressure)),180 'pressure':str(pressure),
177 'humidity':GLib.Variant('s', str(humidity)),181 'humidity':str(humidity),
178 'wind_speed':GLib.Variant('s', str(wind_speed)),182 'wind_speed':str(wind_speed),
179 'wind_direction':GLib.Variant('s', str(wind_direction)),183 'wind_direction':str(wind_direction),
180 'latitude':GLib.Variant('s', str(latitude)),184 'latitude':str(latitude),
181 'longitude':GLib.Variant('s', str(longitude))})185 'longitude':str(longitude),
186 'photo_hint':photo_hint})
182 forecast = weather_search(city_id, 'forecast')187 forecast = weather_search(city_id, 'forecast')
183 if not forecast or not "list" in forecast:188 if not forecast or not "list" in forecast:
184 return results189 return results
@@ -210,18 +215,21 @@
210 except Exception as error:215 except Exception as error:
211 print(error)216 print(error)
212 return results217 return results
213 results.append({'uri':uri+"#"+day_name,218 uri += "#%s" % day_name
219 photo_hint = randrange(20)
220 results.append({'uri':uri,
214 'icon':icon,221 'icon':icon,
215 'title':title,222 'title':title,
216 'comment':description,223 'comment':description,
217 'min_temp':GLib.Variant('s', min_temp),224 'min_temp':min_temp,
218 'max_temp':GLib.Variant('s', max_temp),225 'max_temp':max_temp,
219 'pressure':GLib.Variant('s', str(pressure)),226 'pressure':str(pressure),
220 'humidity':GLib.Variant('s', str(humidity)),227 'humidity':str(humidity),
221 'wind_speed':GLib.Variant('s', str(wind_speed)),228 'wind_speed':str(wind_speed),
222 'wind_direction':GLib.Variant('s', str(wind_direction)),229 'wind_direction':str(wind_direction),
223 'latitude':GLib.Variant('s', str(latitude)),230 'latitude':str(latitude),
224 'longitude':GLib.Variant('s', str(longitude))})231 'longitude':str(longitude),
232 'photo_hint':photo_hint})
225 return results233 return results
226234
227235
@@ -265,7 +273,7 @@
265273
266class Preview (Unity.ResultPreviewer):274class Preview (Unity.ResultPreviewer):
267275
268 def get_image(self,q, lat, lon):276 def get_image(self,rand, q, lat, lon):
269 print (lat, lon)277 print (lat, lon)
270 flick_map={'weather-clear':'clear',278 flick_map={'weather-clear':'clear',
271 'weather-clear-night':'clear',279 'weather-clear-night':'clear',
@@ -305,7 +313,7 @@
305 try:313 try:
306 response = urllib.request.urlopen(uri).read()314 response = urllib.request.urlopen(uri).read()
307 data = json.loads(response.decode('utf-8'))315 data = json.loads(response.decode('utf-8'))
308 photo = randrange(len(data['photos']['photo']))316 photo = min(rand, int(data['photos']['total'])-1)
309 image = data['photos']['photo'][photo]['url_m']317 image = data['photos']['photo'][photo]['url_m']
310 owner = data['photos']['photo'][photo]['ownername']318 owner = data['photos']['photo'][photo]['ownername']
311 license = license_list[int(data['photos']['photo'][photo]['license'])]319 license = license_list[int(data['photos']['photo'][photo]['license'])]
@@ -319,7 +327,8 @@
319 327
320 preview = Unity.GenericPreview.new(self.result.title.split('\n')[0], '', None)328 preview = Unity.GenericPreview.new(self.result.title.split('\n')[0], '', None)
321 preview.props.subtitle = self.result.comment.capitalize()329 preview.props.subtitle = self.result.comment.capitalize()
322 image, owner, license, link = self.get_image(self.result.icon_hint,330 image, owner, license, link = self.get_image(self.result.metadata['photo_hint'].get_int32(),
331 self.result.icon_hint,
323 self.result.metadata['latitude'].get_string(),332 self.result.metadata['latitude'].get_string(),
324 self.result.metadata['longitude'].get_string())333 self.result.metadata['longitude'].get_string())
325334

Subscribers

People subscribed via source and target branches

to all changes: