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
1=== modified file 'data/openweathermap.scope.in'
2--- data/openweathermap.scope.in 2013-03-22 18:18:40 +0000
3+++ data/openweathermap.scope.in 2013-04-17 17:02:34 +0000
4@@ -4,7 +4,7 @@
5 Icon=
6 _Keywords=openweathermap;weather;sky;forecast;
7 RequiredMetadata=
8-OptionalMetadata=min_temp[s];max_temp[s];pressure[s];humidity[s];wind_speed[s];wind_direction[s];latitude[s];longitude[s];
9+OptionalMetadata=min_temp[s];max_temp[s];pressure[s];humidity[s];wind_speed[s];wind_direction[s];latitude[s];longitude[s];photo_hint[i];
10 Loader=/usr/share/unity-scopes/openweathermap/unity_openweathermap_daemon.py
11 RemoteContent=true
12 Type=info
13
14=== modified file 'src/unity_openweathermap_daemon.py'
15--- src/unity_openweathermap_daemon.py 2013-03-26 17:54:44 +0000
16+++ src/unity_openweathermap_daemon.py 2013-04-17 17:02:34 +0000
17@@ -72,7 +72,10 @@
18 m8 = {'id' :'longitude',
19 'type' :'s',
20 'field':Unity.SchemaFieldType.OPTIONAL}
21-EXTRA_METADATA = [m1, m2, m3, m4, m5, m6, m7, m8]
22+m9 = {'id' :'photo_hint',
23+ 'type' :'i',
24+ 'field':Unity.SchemaFieldType.OPTIONAL}
25+EXTRA_METADATA = [m1, m2, m3, m4, m5, m6, m7, m8, m9]
26
27 def weather_search(query, s_type):
28 print (query)
29@@ -167,18 +170,20 @@
30 return results
31 if not uri or not city_id:
32 return results
33+ photo_hint = randrange(20)
34 results.append({'uri':uri,
35 'icon':icon,
36 'title':title,
37 'comment':description,
38- 'min_temp':GLib.Variant('s', min_temp),
39- 'max_temp':GLib.Variant('s', max_temp),
40- 'pressure':GLib.Variant('s', str(pressure)),
41- 'humidity':GLib.Variant('s', str(humidity)),
42- 'wind_speed':GLib.Variant('s', str(wind_speed)),
43- 'wind_direction':GLib.Variant('s', str(wind_direction)),
44- 'latitude':GLib.Variant('s', str(latitude)),
45- 'longitude':GLib.Variant('s', str(longitude))})
46+ 'min_temp':min_temp,
47+ 'max_temp':max_temp,
48+ 'pressure':str(pressure),
49+ 'humidity':str(humidity),
50+ 'wind_speed':str(wind_speed),
51+ 'wind_direction':str(wind_direction),
52+ 'latitude':str(latitude),
53+ 'longitude':str(longitude),
54+ 'photo_hint':photo_hint})
55 forecast = weather_search(city_id, 'forecast')
56 if not forecast or not "list" in forecast:
57 return results
58@@ -210,18 +215,21 @@
59 except Exception as error:
60 print(error)
61 return results
62- results.append({'uri':uri+"#"+day_name,
63+ uri += "#%s" % day_name
64+ photo_hint = randrange(20)
65+ results.append({'uri':uri,
66 'icon':icon,
67 'title':title,
68 'comment':description,
69- 'min_temp':GLib.Variant('s', min_temp),
70- 'max_temp':GLib.Variant('s', max_temp),
71- 'pressure':GLib.Variant('s', str(pressure)),
72- 'humidity':GLib.Variant('s', str(humidity)),
73- 'wind_speed':GLib.Variant('s', str(wind_speed)),
74- 'wind_direction':GLib.Variant('s', str(wind_direction)),
75- 'latitude':GLib.Variant('s', str(latitude)),
76- 'longitude':GLib.Variant('s', str(longitude))})
77+ 'min_temp':min_temp,
78+ 'max_temp':max_temp,
79+ 'pressure':str(pressure),
80+ 'humidity':str(humidity),
81+ 'wind_speed':str(wind_speed),
82+ 'wind_direction':str(wind_direction),
83+ 'latitude':str(latitude),
84+ 'longitude':str(longitude),
85+ 'photo_hint':photo_hint})
86 return results
87
88
89@@ -265,7 +273,7 @@
90
91 class Preview (Unity.ResultPreviewer):
92
93- def get_image(self,q, lat, lon):
94+ def get_image(self,rand, q, lat, lon):
95 print (lat, lon)
96 flick_map={'weather-clear':'clear',
97 'weather-clear-night':'clear',
98@@ -305,7 +313,7 @@
99 try:
100 response = urllib.request.urlopen(uri).read()
101 data = json.loads(response.decode('utf-8'))
102- photo = randrange(len(data['photos']['photo']))
103+ photo = min(rand, int(data['photos']['total'])-1)
104 image = data['photos']['photo'][photo]['url_m']
105 owner = data['photos']['photo'][photo]['ownername']
106 license = license_list[int(data['photos']['photo'][photo]['license'])]
107@@ -319,7 +327,8 @@
108
109 preview = Unity.GenericPreview.new(self.result.title.split('\n')[0], '', None)
110 preview.props.subtitle = self.result.comment.capitalize()
111- image, owner, license, link = self.get_image(self.result.icon_hint,
112+ image, owner, license, link = self.get_image(self.result.metadata['photo_hint'].get_int32(),
113+ self.result.icon_hint,
114 self.result.metadata['latitude'].get_string(),
115 self.result.metadata['longitude'].get_string())
116

Subscribers

People subscribed via source and target branches

to all changes: