Merge lp:~marco-gallotta/ibid/geonames-702810-0.1 into lp:~ibid-core/ibid/old-release-0.1-1.6

Proposed by marcog
Status: Needs review
Proposed branch: lp:~marco-gallotta/ibid/geonames-702810-0.1
Merge into: lp:~ibid-core/ibid/old-release-0.1-1.6
Diff against target: 172 lines (+71/-4) (has conflicts)
4 files modified
ibid/plugins/geography.py (+36/-4)
ibid/plugins/google.py (+16/-0)
ibid/plugins/network.py (+15/-0)
ibid/plugins/social.py (+4/-0)
Text conflict in ibid/plugins/geography.py
Text conflict in ibid/plugins/google.py
Text conflict in ibid/plugins/network.py
Text conflict in ibid/plugins/social.py
To merge this branch: bzr merge lp:~marco-gallotta/ibid/geonames-702810-0.1
Reviewer Review Type Date Requested Status
Stefano Rivera Needs Fixing
Review via email: mp+46612@code.launchpad.net

Commit message

Log geonames status messages and catch cases when results aren't actually present and handle them gracefully.

Description of the change

Log geonames status messages and catch cases when results aren't actually present and handle them gracefully.

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

There's no simplematch in 0.1!

review: Needs Fixing
Revision history for this message
marcog (marco-gallotta) wrote :

> There's no simplematch in 0.1!

Oops! r969

968. By marcog

Merge geonames-702810

969. By marcog

There's no simplematch in 0.1, so revert those changes

Revision history for this message
Stefano Rivera (stefanor) wrote :

conflict!

review: Needs Fixing

Unmerged revisions

969. By marcog

There's no simplematch in 0.1, so revert those changes

968. By marcog

Merge geonames-702810

967. By marcog

Bump copyright date and add my name

966. By marcog

Use the simplified @match regex in Timezone

965. By marcog

Log geonames status messages and check for results before assuming they're there

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/feeds.py'
2=== modified file 'ibid/plugins/geography.py'
3--- ibid/plugins/geography.py 2011-01-12 14:16:31 +0000
4+++ ibid/plugins/geography.py 2011-01-20 11:13:12 +0000
5@@ -1,4 +1,5 @@
6-# Copyright (c) 2009-2010, Jonathan Hitchcock, Michael Gorven, Stefano Rivera
7+# Copyright (c) 2009-2011, Jonathan Hitchcock, Michael Gorven, Stefano Rivera,
8+# Marco Gallotta
9 # Released under terms of the MIT/X/Expat Licence. See COPYING for details.
10
11 from math import acos, sin, cos, radians
12@@ -50,11 +51,19 @@
13 radius_values = DictOption('radius_values', 'Radius of the earth in the units in which to specify distances', default_radius_values)
14
15 def get_place_data(self, place, num):
16+<<<<<<< TREE
17 return json_webservice('http://ws.geonames.org/searchJSON', {'q': place, 'maxRows': num, 'username': 'ibid'})
18+=======
19+ js = json_webservice('http://ws.geonames.org/searchJSON', {'q': place, 'maxRows': num, 'username': 'ibid'})
20+ if 'status' in js:
21+ log.warning(u'Received status "%s" from geonames when searching '
22+ u'for "%s"', js['status'], place)
23+ return js
24+>>>>>>> MERGE-SOURCE
25
26 def get_place(self, place):
27 js = self.get_place_data(place, 1)
28- if js['totalResultsCount'] == 0:
29+ if js.get('totalResultsCount', 0) == 0:
30 return None
31 info = js['geonames'][0]
32 return {'name': "%s, %s, %s" % (info['name'], info['adminName1'], info['countryName']),
33@@ -64,7 +73,7 @@
34 @match(r'^(?:(?:search\s+for\s+place)|(?:place\s+search\s+for)|(?:places\s+for))\s+(\S.+?)\s*$')
35 def placesearch(self, event, place):
36 js = self.get_place_data(place, 10)
37- if js['totalResultsCount'] == 0:
38+ if js.get('totalResultsCount', 0) == 0:
39 event.addresponse(u"I don't know of anywhere even remotely like '%s'", place)
40 else:
41 event.addresponse(u"I can find: %s",
42@@ -317,12 +326,35 @@
43 raise TimezoneException(u"I don't know about the %s timezone" % (string,))
44
45 def _geonames_lookup(self, place):
46+<<<<<<< TREE
47 search = json_webservice('http://ws.geonames.org/searchJSON', {'q': place, 'maxRows': 1, 'username': 'ibid'})
48 if search['totalResultsCount'] == 0:
49+=======
50+ search = json_webservice('http://ws.geonames.org/searchJSON', {
51+ 'q': place,
52+ 'maxRows': 1,
53+ 'username': 'ibid',
54+ })
55+ if 'status' in search:
56+ log.warning(u'Received status "%s" from geonames when searching '
57+ u'for "%s"', search['status'], place)
58+ if search.get('totalResultsCount', 0) == 0:
59+>>>>>>> MERGE-SOURCE
60 return None
61
62 city = search['geonames'][0]
63+<<<<<<< TREE
64 timezone = json_webservice('http://ws.geonames.org/timezoneJSON', {'lat': city['lat'], 'lng': city['lng'], 'username': 'ibid'})
65+=======
66+ timezone = json_webservice('http://ws.geonames.org/timezoneJSON', {
67+ 'lat': city['lat'],
68+ 'lng': city['lng'],
69+ 'username': 'ibid',
70+ })
71+ if 'status' in timezone:
72+ log.warning(u'Received status "%s" from geonames when looking up '
73+ u'lat %s lng %s', search['status'], city['lat'], city['lng'])
74+>>>>>>> MERGE-SOURCE
75
76 if 'timezoneId' in timezone:
77 return gettz(timezone['timezoneId'])
78@@ -331,7 +363,7 @@
79 offset = timezone['rawOffset']
80 return tzoffset('UTC%s%s' % (offset>=0 and '+' or '', offset), offset*3600)
81
82- @match(r'^when\s+is\s+((?:[0-9.:/hT -]|%s)+)(?:\s+in)?(?:\s+(.+))?\s+in\s+(.+)$' % '|'.join(MONTH_SHORT+MONTH_LONG+OTHER_STUFF))
83+ @match(r'^when \s+is\s+((?:[0-9.:/hT -]|%s)+)(?:\s+in)?(?:\s+(.+))?\s+in\s+(.+)$' % '|'.join(MONTH_SHORT+MONTH_LONG+OTHER_STUFF), simple=False)
84 def convert(self, event, time, from_, to):
85 try:
86 source = time and parse(time) or datetime.now()
87
88=== modified file 'ibid/plugins/google.py'
89--- ibid/plugins/google.py 2011-01-19 19:21:58 +0000
90+++ ibid/plugins/google.py 2011-01-20 11:13:12 +0000
91@@ -107,6 +107,7 @@
92 def calc(self, event, expression):
93 tree = self._google_scrape_search(expression)
94
95+<<<<<<< TREE
96 nodes = [node for node in tree.findall('.//h2/b')]
97 if len(nodes) == 1:
98 # ElementTree doesn't support inline tags:
99@@ -122,6 +123,21 @@
100 node = decode_htmlentities(node)
101 event.addresponse(node)
102 else:
103+=======
104+ nodes = [node for node in tree.findall('.//h2/b')]
105+ if len(nodes) == 1:
106+ # ElementTree doesn't support inline tags:
107+ # May return ASCII unless an encoding is specified.
108+ # "utf8" will result in an xml header
109+ node = ElementTree.tostring(nodes[0], encoding='utf-8')
110+ node = node.decode('utf-8')
111+ node = re.sub(r'^<b>(.*)</b>$', lambda x: x.group(1), node)
112+ node = re.sub(r'<sup>(.*?)</sup>',
113+ lambda x: u'^' + x.group(1), node)
114+ node = decode_htmlentities(node)
115+ event.addresponse(node)
116+ else:
117+>>>>>>> MERGE-SOURCE
118 event.addresponse(u'No result')
119
120 @match(r'^gdefine\s+(.+)$')
121
122=== modified file 'ibid/plugins/network.py'
123--- ibid/plugins/network.py 2011-01-16 22:57:11 +0000
124+++ ibid/plugins/network.py 2011-01-20 11:13:12 +0000
125@@ -272,6 +272,7 @@
126 }
127
128 if action.upper() == 'GET':
129+<<<<<<< TREE
130 got_title = False
131 content_type = self._get_header(headers, 'content-type')
132 if content_type and (content_type.startswith('text/html') or
133@@ -284,6 +285,20 @@
134
135 if not got_title and content_type:
136 reply += u' ' + content_type
137+=======
138+ got_title = False
139+ content_type = self._get_header(headers, 'content-type')
140+ if (content_type.startswith('text/html') or
141+ content_type.startswith('application/xhtml+xml')):
142+ match = re.search(r'<title>(.*)<\/title>', data,
143+ re.I | re.DOTALL)
144+ if match:
145+ got_title = True
146+ reply += u' "%s"' % match.groups()[0].strip()
147+
148+ if not got_title:
149+ reply += u' ' + content_type
150+>>>>>>> MERGE-SOURCE
151
152 event.addresponse(reply)
153
154
155=== modified file 'ibid/plugins/oeis.py'
156=== modified file 'ibid/plugins/social.py'
157--- ibid/plugins/social.py 2011-01-19 19:22:40 +0000
158+++ ibid/plugins/social.py 2011-01-20 11:13:12 +0000
159@@ -119,9 +119,13 @@
160 event.addresponse(u'That %s is private', service['name'])
161 elif e.code == 404:
162 event.addresponse(u'No such %s', service['name'])
163+<<<<<<< TREE
164 else:
165 log.debug(u'%s returned HTTP code %i: %s', service['name'],
166 e.code, e.reason)
167+=======
168+ elif e.code == 500:
169+>>>>>>> MERGE-SOURCE
170 event.addresponse(u'I can only see the Fail Whale')
171
172 @handler

Subscribers

People subscribed via source and target branches