Merge lp:~knitzsche/ubuntu-rest-scopes/fix-10-day-forecast-url into lp:ubuntu-rest-scopes

Proposed by Kyle Nitzsche
Status: Needs review
Proposed branch: lp:~knitzsche/ubuntu-rest-scopes/fix-10-day-forecast-url
Merge into: lp:ubuntu-rest-scopes
Diff against target: 90 lines (+10/-10)
2 files modified
src/scopes/tests/test_weatherchannel.py (+5/-5)
src/scopes/weatherchannel.py (+5/-5)
To merge this branch: bzr merge lp:~knitzsche/ubuntu-rest-scopes/fix-10-day-forecast-url
Reviewer Review Type Date Requested Status
Kyle Nitzsche (community) Abstain
Facundo Batista (community) Needs Fixing
Review via email: mp+307347@code.launchpad.net

Description of the change

Ensure that the url used to open the 10-day forecast on weather.com uses lat and long of sufficient precision to avoid 404 style error when user taps Open on Preview from Today scope.

To post a comment you must log in.
Revision history for this message
Facundo Batista (facundo) wrote :

Ah, it's a good catch that the URL needs a 5 digit precision (even if the numbers are completed with zeros).

A detail in the formatting: the 2 as width doesn't make sense, as if you request 5 digits for precision, it always will be greater than 2, so please remove it.

Also, please include this formatting change in the ENGLISH_URL_TEMPLATE itself, no need to prebuild other string.

Thanks!!

review: Needs Fixing
Revision history for this message
Facundo Batista (facundo) wrote :

It will also be great if you include a test case where it shows that this change is needed, thanks!

535. By Kyle Nitzsche

weatherchannel.py:
* don't prebuild string to set lat and lng for url
* improve the format specifier
* also apply format to URL_TEMPLATE so lat an lng have 5 digit precisions

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

Hey Facundo:

Do want a unit test that *fails* when a URL is sent to weather.com with insufficient lat/lng precision? (who knows - they might fix their issue and someday such URLs could succeed.)

Or is this url (pulled from bug reporters log) enough:

https://weather.com/weather/10day/l/47,8?par=ubuntu_bq

See also: https://bugs.launchpad.net/ubuntu-rest-scopes/+bug/1588997/comments/8

Revision history for this message
Facundo Batista (facundo) wrote :

That URL is enough... I mean, make a test that would end up producing a URL with latitude=47 and longitude=8, and assert that correct URL is returned in the response.

Thanks!

536. By Kyle Nitzsche

modify weatherchannel tests to ensure that the actual url produced has
five digit percision.

Revision history for this message
Facundo Batista (facundo) wrote :

Please include this formatting change in the ENGLISH_URL_TEMPLATE itself, no need to prebuild other string.

review: Needs Fixing
Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

Hi Facundo,

I don't understand :) I do not prebuild any other string, and the format is applied directly to the ENGLISH_URL_TEMPLATE itself lines 64-65, and to URL_TEMPLATE lines 72-73.

(the only other changes were to for tests and in these cases I only modified the hard coded url strings.)

Revision history for this message
Facundo Batista (facundo) wrote :

You're doing

     latitude="{:.5f}".format(latitude),

to put a pre-formatted latitude in URL_TEMPLATE or ENGLISH_URL_TEMPLATE.

Instead of that, just add the ":.5f" format modifier to the URL_TEMPLATE or ENGLISH_URL_TEMPLATE themselves.

537. By Kyle Nitzsche

add the ":.5f" format modifier to the URL_TEMPLATE or ENGLISH_URL_TEMPLATE
themselves, per review request

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

Facundo, how's this? :) (I forgot about this for a while ...)

review: Needs Resubmitting
Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

I set this to "Resubmit" thinking that meant "I've Resubmitted", which is probably incorrect.

Anyway, it is ready for review.

Revision history for this message
Kyle Nitzsche (knitzsche) :
review: Abstain

Unmerged revisions

537. By Kyle Nitzsche

add the ":.5f" format modifier to the URL_TEMPLATE or ENGLISH_URL_TEMPLATE
themselves, per review request

536. By Kyle Nitzsche

modify weatherchannel tests to ensure that the actual url produced has
five digit percision.

535. By Kyle Nitzsche

weatherchannel.py:
* don't prebuild string to set lat and lng for url
* improve the format specifier
* also apply format to URL_TEMPLATE so lat an lng have 5 digit precisions

534. By Kyle Nitzsche

fixes lp:1629243

533. By Kyle Nitzsche

create url used from preview to open weatherchannel.com web page
with 10-day forecast with latitude and longitude that has 5 digit
precisions, as seems to be required.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/scopes/tests/test_weatherchannel.py'
2--- src/scopes/tests/test_weatherchannel.py 2016-06-07 14:01:21 +0000
3+++ src/scopes/tests/test_weatherchannel.py 2016-11-10 20:52:05 +0000
4@@ -37,7 +37,7 @@
5 self.assertEqual(response[0]['category']['title'], u'SE1, England, GB')
6
7 # the two big items, the first very detailed for sanity check
8- url = 'https://weather.com/weather/today/l/123,456?par=ptest'
9+ url = 'https://weather.com/weather/today/l/123.00000,456.00000?par=ptest'
10 comment = u'Light rain. Low 4\xbaC.'
11 self.assertDictEqual(response[1], dict(result={
12 'art': 'foo/weatherchannel/suru/weather-showers.svg',
13@@ -207,7 +207,7 @@
14 self.assertEqual(response[0]['category']['title'], u'SE1, 英格兰, GB')
15
16 # the result
17- url = 'https://weather.com/weather/today/l/123,456?par=ptest'
18+ url = 'https://weather.com/weather/today/l/123.00000,456.00000?par=ptest'
19 comment = u'\u5c11\u4e91\u3002 \u6700\u4f4e 4\xbaC\u3002'
20 self.assertDictEqual(response[1], dict(result={
21 'art': 'foo/weatherchannel/suru/weather-clouds-night.svg',
22@@ -399,7 +399,7 @@
23 'icon': None,
24 'id': 'action1',
25 'label': '10 day forecast',
26- 'uri': 'https://weather.com/weather/10day/l/123,456?par=ptest'
27+ 'uri': 'https://weather.com/weather/10day/l/123.00000,456.00000?par=ptest'
28 }],
29 }))
30
31@@ -604,7 +604,7 @@
32 self.assertEqual(len(resp), 11)
33
34 self.assertDictEqual(resp[0], {
35- 'url': 'https://weather.com/weather/today/l/123,456?par=ptest',
36+ 'url': 'https://weather.com/weather/today/l/123.00000,456.00000?par=ptest',
37 'art': 'foo/weatherchannel/suru/weather-showers.svg',
38 'art_wlogo': 'foo/weatherchannel/suru/weather-showers-wlogo.svg',
39 'day': u'Tonight',
40@@ -627,7 +627,7 @@
41 })
42
43 self.assertDictEqual(resp[1], {
44- 'url': 'https://weather.com/weather/10day/l/123,456?par=ptest',
45+ 'url': 'https://weather.com/weather/10day/l/123.00000,456.00000?par=ptest',
46 'art': 'foo/weatherchannel/suru/weather-clouds.svg',
47 'art_wlogo': 'foo/weatherchannel/suru/weather-clouds-wlogo.svg',
48 'day': u'Tomorrow',
49
50=== modified file 'src/scopes/weatherchannel.py'
51--- src/scopes/weatherchannel.py 2016-06-07 14:01:21 +0000
52+++ src/scopes/weatherchannel.py 2016-11-10 20:52:05 +0000
53@@ -81,8 +81,8 @@
54 for icon, wids in _icons_map:
55 WEATHER_ICONS_MAP.update(dict.fromkeys(wids, icon))
56
57-URL_TEMPLATE = 'https://weather.com/{language}/weather/{hint}/l/{latitude},{longitude}?par={partner}' # NOQA
58-ENGLISH_URL_TEMPLATE = 'https://weather.com/weather/{hint}/l/{latitude},{longitude}?par={partner}'
59+URL_TEMPLATE = 'https://weather.com/{language}/weather/{hint}/l/{latitude:.5f},{longitude:.5f}?par={partner}' # NOQA
60+ENGLISH_URL_TEMPLATE = 'https://weather.com/weather/{hint}/l/{latitude:.5f},{longitude:.5f}?par={partner}'
61
62 # the categories to use
63 CATEGORY_GRID_MAIN = {
64@@ -259,6 +259,7 @@
65
66 def get_localized_url(self, hint, latitude, longitude):
67 """Build a localized URL with several parameters."""
68+ #ensure url has lat & long of sufficient length
69 if self.language.startswith('en-') or self.language == 'en':
70 # TWC URLs english are special
71 return ENGLISH_URL_TEMPLATE.format(
72@@ -269,8 +270,8 @@
73 else:
74 return URL_TEMPLATE.format(
75 hint=hint,
76- latitude=latitude,
77- longitude=longitude,
78+ latitude="{:.5f}".format(latitude),
79+ longitude="{:.5f}".format(longitude),
80 language=self.language,
81 partner=self.auth['partner'])
82
83@@ -395,7 +396,6 @@
84 location_info['ccode'])))
85
86 url = self.get_localized_url(uri_date, latitude, longitude)
87-
88 # improve conditions, in case got nothing from TWC
89 conditions = daily_info['conditions']
90 if not conditions:

Subscribers

People subscribed via source and target branches