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
1=== modified file 'src/unity_yahoostock_daemon.py'
2--- src/unity_yahoostock_daemon.py 2013-05-22 20:06:13 +0000
3+++ src/unity_yahoostock_daemon.py 2013-09-25 19:11:08 +0000
4@@ -15,12 +15,14 @@
5 # You should have received a copy of the GNU General Public License along
6 # with this program. If not, see <http://www.gnu.org/licenses/>.
7
8-from gi.repository import Unity, UnityExtras
9-from gi.repository import Gio, GLib
10+from gi.repository import Unity
11+from gi.repository import Gio
12 import urllib.parse
13 import urllib.request
14 import feedparser
15 import gettext
16+import logging
17+
18 from datetime import datetime
19
20
21@@ -69,6 +71,8 @@
22 # Test injection
23 FAKE_CALL = False
24
25+logger = logging.getLogger("unity.scope.yahoostock")
26+
27 def search(search, filters):
28 '''
29 Any search method returning results as a list of tuples.
30@@ -87,14 +91,16 @@
31 if not search:
32 return results
33 ys = Yahoostock()
34+ logger.debug("Getting quotes for: %r", search)
35 quotes = ys.getQuotes(urllib.parse.quote(search))
36+ logger.debug("Found %s quotes.", len(quotes))
37 for quote in quotes:
38 volume_str = ys.getVolumeStr(quote['volume'])
39 change_str = ys.getChangeStr(quote['change'])
40 comment = "%s\n%s@%s\n%s\n%s" % (quote['name'],
41 quote['lastVal'], quote['lastTime'],
42 volume_str, change_str)
43- print (quote['symbol'])
44+ logger.debug("quote: %s - %s", quote['symbol'], search)
45 if quote['name'] == 'Invalid Symbol' or quote['lastVal'] == '0.00':
46 return results
47 results.append({'uri':ys.getQuoteUrl(quote['symbol']),
48@@ -162,21 +168,20 @@
49 try:
50 quote = self._parseLine(line.decode('utf-8'))
51 quotes.append(quote)
52- except Exception as error:
53- print(error)
54+ except Exception:
55+ logger.exception("Error while parsing data.")
56 return quotes
57
58 # this expects to be passed in a string like this:
59 # HPQ+A+RHT+GM no spaces!
60 def getQuotes(self, symbols):
61 url = QUOTE_URL % (symbols)
62- print(url)
63 stream = urllib.request.urlopen(url)
64 if stream is not None:
65 if stream.getcode() is 200 or FAKE_CALL is True:
66 return self._parseData(stream)
67 else:
68- print ("error: http returned %d" % (stream.getcode()))
69+ logger.warning("error: http returned %d", stream.getcode())
70 stream.close()
71 return []
72
73@@ -213,8 +218,8 @@
74 story["description"] = ""
75 stories.append(story)
76 count = count + 1
77- except Exception as e:
78- print ("Exception: ", e)
79+ except Exception:
80+ logger.exception("Error while getting news for: %r", symbol)
81 if count >= maxitems:
82 break
83 return stories
84@@ -237,8 +242,8 @@
85 else:
86 # unch
87 arrow = chr(8594)
88- except Exception as e:
89- print ("Exception: ", e)
90+ except Exception:
91+ logger.exception("Error while getting change string.")
92 return ""
93 return "%s %s (%s)" % (arrow, changeFlt, changePct)
94
95@@ -253,12 +258,11 @@
96 return _("Vol: ") + str(round(fVol / 1000, 3)) + "k"
97 else:
98 return _("Vol: ") + volume
99- except Exception as e:
100- print ("Exception: ", e)
101+ except Exception:
102+ logger.exception("Error while getting volume string.")
103 return ""
104
105
106-
107 # Classes below this point establish communication
108 # with Unity, you probably shouldn't modify them.
109
110@@ -293,8 +297,8 @@
111 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
112 i['dnd_uri'] = i['uri']
113 result_set.add_result(**i)
114- except Exception as error:
115- print (error)
116+ except Exception:
117+ logger.exception("Error while building result set.")
118
119 class Preview (Unity.ResultPreviewer):
120
121
122=== modified file 'tests/test_yahoostock.py'
123--- tests/test_yahoostock.py 2013-04-25 10:31:50 +0000
124+++ tests/test_yahoostock.py 2013-09-25 19:11:08 +0000
125@@ -24,7 +24,7 @@
126 def perform_query(self, query, filter_set = Unity.FilterSet.new()):
127 result_set = ResultSet()
128 ctx = Unity.SearchContext.create(query, 0, filter_set,
129- None, result_set, None)
130+ {}, result_set, None)
131 s = self.scope.create_search_for_query(ctx)
132 s.run()
133 return result_set

Subscribers

People subscribed via source and target branches