Merge lp:~verterok/unity-scope-yahoostock/ystock-logging into lp:unity-scope-yahoostock

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: David Callé
Approved revision: 56
Merged at revision: 55
Proposed branch: lp:~verterok/unity-scope-yahoostock/ystock-logging
Merge into: lp:unity-scope-yahoostock
Diff against target: 133 lines (+21/-17)
2 files modified
src/unity_yahoostock_daemon.py (+20/-16)
tests/test_yahoostock.py (+1/-1)
To merge this branch: bzr merge lp:~verterok/unity-scope-yahoostock/ystock-logging
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
David Callé Approve
Review via email: mp+187380@code.launchpad.net

Commit message

Add basic logging (replace print with logging)

Description of the change

Add basic logging (replace print with logging)

To post a comment you must log in.
Revision history for this message
David Callé (davidc3) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
56. By Guillermo Gonzalez

fix test

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/unity_yahoostock_daemon.py'
--- src/unity_yahoostock_daemon.py 2013-05-22 20:06:13 +0000
+++ src/unity_yahoostock_daemon.py 2013-09-25 19:11:08 +0000
@@ -15,12 +15,14 @@
15# You should have received a copy of the GNU General Public License along15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.16# with this program. If not, see <http://www.gnu.org/licenses/>.
1717
18from gi.repository import Unity, UnityExtras18from gi.repository import Unity
19from gi.repository import Gio, GLib19from gi.repository import Gio
20import urllib.parse20import urllib.parse
21import urllib.request21import urllib.request
22import feedparser22import feedparser
23import gettext23import gettext
24import logging
25
24from datetime import datetime26from datetime import datetime
2527
2628
@@ -69,6 +71,8 @@
69# Test injection71# Test injection
70FAKE_CALL = False72FAKE_CALL = False
7173
74logger = logging.getLogger("unity.scope.yahoostock")
75
72def search(search, filters):76def search(search, filters):
73 '''77 '''
74 Any search method returning results as a list of tuples.78 Any search method returning results as a list of tuples.
@@ -87,14 +91,16 @@
87 if not search:91 if not search:
88 return results92 return results
89 ys = Yahoostock()93 ys = Yahoostock()
94 logger.debug("Getting quotes for: %r", search)
90 quotes = ys.getQuotes(urllib.parse.quote(search))95 quotes = ys.getQuotes(urllib.parse.quote(search))
96 logger.debug("Found %s quotes.", len(quotes))
91 for quote in quotes:97 for quote in quotes:
92 volume_str = ys.getVolumeStr(quote['volume'])98 volume_str = ys.getVolumeStr(quote['volume'])
93 change_str = ys.getChangeStr(quote['change'])99 change_str = ys.getChangeStr(quote['change'])
94 comment = "%s\n%s@%s\n%s\n%s" % (quote['name'],100 comment = "%s\n%s@%s\n%s\n%s" % (quote['name'],
95 quote['lastVal'], quote['lastTime'],101 quote['lastVal'], quote['lastTime'],
96 volume_str, change_str)102 volume_str, change_str)
97 print (quote['symbol'])103 logger.debug("quote: %s - %s", quote['symbol'], search)
98 if quote['name'] == 'Invalid Symbol' or quote['lastVal'] == '0.00':104 if quote['name'] == 'Invalid Symbol' or quote['lastVal'] == '0.00':
99 return results105 return results
100 results.append({'uri':ys.getQuoteUrl(quote['symbol']),106 results.append({'uri':ys.getQuoteUrl(quote['symbol']),
@@ -162,21 +168,20 @@
162 try:168 try:
163 quote = self._parseLine(line.decode('utf-8'))169 quote = self._parseLine(line.decode('utf-8'))
164 quotes.append(quote)170 quotes.append(quote)
165 except Exception as error:171 except Exception:
166 print(error)172 logger.exception("Error while parsing data.")
167 return quotes173 return quotes
168174
169 # this expects to be passed in a string like this:175 # this expects to be passed in a string like this:
170 # HPQ+A+RHT+GM no spaces!176 # HPQ+A+RHT+GM no spaces!
171 def getQuotes(self, symbols):177 def getQuotes(self, symbols):
172 url = QUOTE_URL % (symbols)178 url = QUOTE_URL % (symbols)
173 print(url)
174 stream = urllib.request.urlopen(url)179 stream = urllib.request.urlopen(url)
175 if stream is not None:180 if stream is not None:
176 if stream.getcode() is 200 or FAKE_CALL is True:181 if stream.getcode() is 200 or FAKE_CALL is True:
177 return self._parseData(stream)182 return self._parseData(stream)
178 else:183 else:
179 print ("error: http returned %d" % (stream.getcode()))184 logger.warning("error: http returned %d", stream.getcode())
180 stream.close()185 stream.close()
181 return []186 return []
182187
@@ -213,8 +218,8 @@
213 story["description"] = ""218 story["description"] = ""
214 stories.append(story)219 stories.append(story)
215 count = count + 1220 count = count + 1
216 except Exception as e:221 except Exception:
217 print ("Exception: ", e)222 logger.exception("Error while getting news for: %r", symbol)
218 if count >= maxitems:223 if count >= maxitems:
219 break224 break
220 return stories225 return stories
@@ -237,8 +242,8 @@
237 else:242 else:
238 # unch243 # unch
239 arrow = chr(8594)244 arrow = chr(8594)
240 except Exception as e:245 except Exception:
241 print ("Exception: ", e)246 logger.exception("Error while getting change string.")
242 return ""247 return ""
243 return "%s %s (%s)" % (arrow, changeFlt, changePct)248 return "%s %s (%s)" % (arrow, changeFlt, changePct)
244249
@@ -253,12 +258,11 @@
253 return _("Vol: ") + str(round(fVol / 1000, 3)) + "k"258 return _("Vol: ") + str(round(fVol / 1000, 3)) + "k"
254 else:259 else:
255 return _("Vol: ") + volume260 return _("Vol: ") + volume
256 except Exception as e:261 except Exception:
257 print ("Exception: ", e)262 logger.exception("Error while getting volume string.")
258 return ""263 return ""
259264
260265
261
262# Classes below this point establish communication266# Classes below this point establish communication
263# with Unity, you probably shouldn't modify them.267# with Unity, you probably shouldn't modify them.
264268
@@ -293,8 +297,8 @@
293 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':297 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
294 i['dnd_uri'] = i['uri']298 i['dnd_uri'] = i['uri']
295 result_set.add_result(**i)299 result_set.add_result(**i)
296 except Exception as error:300 except Exception:
297 print (error)301 logger.exception("Error while building result set.")
298302
299class Preview (Unity.ResultPreviewer):303class Preview (Unity.ResultPreviewer):
300304
301305
=== modified file 'tests/test_yahoostock.py'
--- tests/test_yahoostock.py 2013-04-25 10:31:50 +0000
+++ tests/test_yahoostock.py 2013-09-25 19:11:08 +0000
@@ -24,7 +24,7 @@
24 def perform_query(self, query, filter_set = Unity.FilterSet.new()):24 def perform_query(self, query, filter_set = Unity.FilterSet.new()):
25 result_set = ResultSet()25 result_set = ResultSet()
26 ctx = Unity.SearchContext.create(query, 0, filter_set,26 ctx = Unity.SearchContext.create(query, 0, filter_set,
27 None, result_set, None)27 {}, result_set, None)
28 s = self.scope.create_search_for_query(ctx)28 s = self.scope.create_search_for_query(ctx)
29 s.run()29 s.run()
30 return result_set30 return result_set

Subscribers

People subscribed via source and target branches