diff -Nru unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/data/yahoostock.scope.in unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/data/yahoostock.scope.in --- unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/data/yahoostock.scope.in 2013-04-10 07:33:49.000000000 +0000 +++ unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/data/yahoostock.scope.in 2013-05-07 07:23:01.000000000 +0000 @@ -1,16 +1,16 @@ [Scope] DBusName=com.canonical.Unity.Scope.News.Yahoostock DBusPath=/com/canonical/unity/scope/news/yahoostock -Icon= +Icon=/usr/share/icons/unity-icon-theme/places/svg/service-yahoofinance.svg _Keywords=yahoo;stock;market;price; RequiredMetadata= OptionalMetadata=stock[s]; Loader=/usr/share/unity-scopes/yahoostock/unity_yahoostock_daemon.py RemoteContent=true Type=news -_Name=Yahoo Stock -_Description=Find Yahoo Stock Quotes -_SearchHint=Search Yahoo Stock +_Name=Yahoo Finance +_Description=This is an Ubuntu search plugin that enables information from Yahoo Finance to be searched and displayed in the Dash underneath the News header. If you do not wish to search this content source, you can disable this search plugin. +_SearchHint=Search Yahoo Finance [Desktop Entry] X-Ubuntu-Gettext-Domain=unity-scope-yahoostock diff -Nru unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/debian/changelog unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/debian/changelog --- unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/debian/changelog 2013-05-07 16:48:23.000000000 +0000 +++ unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/debian/changelog 2013-05-07 16:48:23.000000000 +0000 @@ -1,3 +1,10 @@ +unity-scope-yahoostock (0.1daily13.05.07ubuntu.unity.experimental.certified-0ubuntu1) raring; urgency=low + + * Automatic snapshot from revision 47 (ubuntu-unity/experimental- + certified) + + -- Ubuntu daily release Tue, 07 May 2013 07:23:38 +0000 + unity-scope-yahoostock (0.1daily13.04.10ubuntu.unity.experimental.certified-0ubuntu1) raring; urgency=low * Initial release diff -Nru unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/src/unity_yahoostock_daemon.py unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/src/unity_yahoostock_daemon.py --- unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/src/unity_yahoostock_daemon.py 2013-04-10 07:33:49.000000000 +0000 +++ unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/src/unity_yahoostock_daemon.py 2013-05-07 07:23:01.000000000 +0000 @@ -21,6 +21,8 @@ import urllib.request import feedparser import gettext +from datetime import datetime + APP_NAME = 'unity-scope-yahoostock' LOCAL_PATH = '/usr/share/locale/' @@ -34,10 +36,12 @@ NO_RESULTS_HINT = _('Sorry, there are no Stock Quotes that match your search.') PROVIDER_CREDITS = _('Powered by Yahoo! Finance') SVG_DIR = '/usr/share/icons/unity-icon-theme/places/svg/' -PROVIDER_ICON = SVG_DIR+'service-yahoostock.svg' +PROVIDER_ICON = SVG_DIR+'service-yahoofinance.svg' DEFAULT_RESULT_ICON = SVG_DIR+'result-news.svg' DEFAULT_RESULT_MIMETYPE = 'text/html' DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT +ICON_SIZE_RESULT = 133 +ICON_SIZE_PREVIEW = 380 c1 = {'id' :'recent', 'name' :_('Quotes'), @@ -94,19 +98,12 @@ if quote['name'] == 'Invalid Symbol' or quote['lastVal'] == '0.00': return results results.append({'uri':ys.getQuoteUrl(quote['symbol']), - 'icon':'http://chart.finance.yahoo.com/t?s=%s&lang=en-US®ion=US&width=133&height=133' % quote['symbol'], + 'icon':'http://chart.finance.yahoo.com/t?s=%s&lang=en-US®ion=US&width=%i&height=%i' % (quote['symbol'], ICON_SIZE_RESULT, ICON_SIZE_RESULT), 'title':quote['symbol'], 'comment':comment, - 'stock':GLib.Variant('s',quote['symbol'])}) - if len(quotes) == 1: - stories = ys.getNewsForSymbol(quote['symbol'], 8) - for story in stories: - results.append({'uri':story['link'], - 'icon_hint':'news-feed', - 'category':1, - 'title':story['title'], - 'comment':story['date'], - 'stock':GLib.Variant('s',quote['symbol'])}) + 'stock':quote['symbol'], + 'last_date':quote['lastDate'], + 'evolution':quote['change']}) return results class Yahoostock: @@ -295,22 +292,53 @@ i['comment'] = '' if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '': i['dnd_uri'] = i['uri'] - i['metadata'] = {} - if EXTRA_METADATA: - for e in i: - for m in EXTRA_METADATA: - if m['id'] == e: - i['metadata'][e] = i[e] - i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS) - result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']), - i['category'], i['result_type'], - str(i['mimetype']), str(i['title']), - str(i['comment']), str(i['dnd_uri']), - i['metadata']) - result_set.add_result(result) + result_set.add_result(**i) except Exception as error: print (error) +class Preview (Unity.ResultPreviewer): + + def do_run(self): + graph = Gio.FileIcon.new(Gio.file_new_for_uri(self.result.icon_hint.replace('=%i' % ICON_SIZE_RESULT, '=%i'% ICON_SIZE_PREVIEW))) + corp = self.result.comment.split('\n')[0] + value = self.result.comment.split('\n')[1].split('@')[0] + time = self.result.comment.split('\n')[1].split('@')[1] + volume = self.result.comment.split('\n')[2].split("Vol: ")[1] + trend = self.result.metadata['evolution'].get_string() + trends = trend.split(' ') + date = self.result.metadata['last_date'].get_string() + delta = datetime.today() - datetime.strptime(date, '%m/%d/%Y') + if delta.days == 1: + date = _('Yesterday') + elif delta.days > 1: + date = _('%i days ago' % delta.days) + else: + date = None + preview = Unity.GenericPreview.new(corp, '', graph) + if date: + preview.props.subtitle = '%s, %s' % (date, time) + else: + preview.props.subtitle = time + if len(trends) > 1: + if trends[0] != trends[-1]: + trend = '%s (%s)' % (trends[0], trends[-1]) + else: + trend = trends[0] + if trend.startswith('-'): + change_arrow = u"\u2B0A" + trend = '%s %s' % (change_arrow, trend[1:]) + else: + change_arrow = u"\u2B08" + trend = '%s %s' % (change_arrow, trend[1:]) + preview.add_info(Unity.InfoHint.new("evolution", _("Evolution"), None, trend)) + preview.add_info(Unity.InfoHint.new("value", _("Value"), None, value)) + preview.add_info(Unity.InfoHint.new("volume", _("Volume"), None, volume)) + preview.add_info(Unity.InfoHint.new("symbol", _("Symbol"), None, self.result.title)) + icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON)) + view_action = Unity.PreviewAction.new("open", _("View"), icon) + preview.add_action(view_action) + return preview + class Scope (Unity.AbstractScope): def __init__(self): Unity.AbstractScope.__init__(self) @@ -362,5 +390,11 @@ se = MySearch (search_context) return se + def do_create_previewer(self, result, metadata): + rp = Preview() + rp.set_scope_result(result) + rp.set_search_metadata(metadata) + return rp + def load_scope(): return Scope() diff -Nru unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/tests/test_yahoostock.py unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/tests/test_yahoostock.py --- unity-scope-yahoostock-0.1daily13.04.10ubuntu.unity.experimental.certified/tests/test_yahoostock.py 2013-04-10 07:33:49.000000000 +0000 +++ unity-scope-yahoostock-0.1daily13.05.07ubuntu.unity.experimental.certified/tests/test_yahoostock.py 2013-05-07 07:23:01.000000000 +0000 @@ -59,16 +59,6 @@ print (result_set.results) self.assertEqual(len(result_set.results), 0) - def test_news_searches(self): - self.scope_module.QUOTE_URL = 'file:tests/data/mock_yahoostock_%s_pass' - self.scope_module.NEWS_URL = 'file:tests/data/mock_yahoostocknews_%s_pass' - self.scope_module.FAKE_CALL = True - expected_results = [''] - results = [] - for s in ['GOOG']: - result_set = self.perform_query(s) - self.assertEqual(len(result_set.results), 9) - def test_failing_search(self): self.scope_module.QUOTE_URL = 'file:tests/data/mock_yahoostock_%s_fail' @@ -78,13 +68,5 @@ result_set = self.perform_query(s) self.assertEqual(len(result_set.results), 0) - def test_failing_news_search(self): - self.scope_module.QUOTE_URL = 'file:tests/data/mock_yahoostock_%s_pass' - self.scope_module.NEWS_URL = 'file:tests/data/mock_yahoostock_%s_fail' - self.scope_module.FAKE_CALL = True - for s in ['GOOG']: - result_set = self.perform_query(s) - self.assertEqual(len(result_set.results), 1) - if __name__ == '__main__': unittest.main()