diff --git a/README.md b/README.md index b4aee675..6ec78a04 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Dependencies list: * [Requests](http://www.python-requests.org/en/latest/) 2.2.1: [Recommended download site](https://pypi.python.org/pypi/requests/2.2.1) * [Requests-oauthlib](https://github.com/requests/requests-oauthlib) 0.4.0 * [Suds](https://fedorahosted.org/suds) 0.4: [Recommended download site](https://pypi.python.org/pypi/suds/0.4) +* [Pygeocoder: ](http://code.xster.net/pygeocoder/wiki/Home) You can install this dependency by using pip or easy_install. * Bootstrap 1.2.1: included in dependencies directory. Copy the bootstrap.exe file corresponding to the desired platform in the windows folder, inside this repository. This dependency has been built using pure basic 4.61. Its source can be found at http://hg.q-continuum.net/updater diff --git a/src/Conf.defaults b/src/Conf.defaults index 3c73f0ae..f70612f0 100644 --- a/src/Conf.defaults +++ b/src/Conf.defaults @@ -88,3 +88,5 @@ search = string(default="control+win+-") edit_keystrokes = string(default="control+win+k") view_user_lists = string(default="control+win+l") get_more_items = string(default="alt+win+pageup") +reverse_geocode = string(default="control+win+g") +view_reverse_geocode = string(default="control+win+shift+g") \ No newline at end of file diff --git a/src/gui/buffers/base.py b/src/gui/buffers/base.py index 2c85a5fe..acd2a35c 100644 --- a/src/gui/buffers/base.py +++ b/src/gui/buffers/base.py @@ -158,6 +158,8 @@ class basePanel(wx.Panel): self.list.list.SetString(self.list.get_selected(), " ".join(self.compose_function(self.db.settings[self.name_buffer][self.list.get_selected()], self.db))) if twitter.utils.is_audio(tweet): sound.player.play("audio.ogg", False) + if twitter.utils.is_geocoded(tweet): + sound.player.play("geo.mp3", False) def start_streams(self): if self.name_buffer == "sent": diff --git a/src/gui/main.py b/src/gui/main.py index b718ac54..bc9ede38 100644 --- a/src/gui/main.py +++ b/src/gui/main.py @@ -34,6 +34,8 @@ import urllib2 import sysTrayIcon import switchModule import languageHandler +import pygeocoder +from pygeolib import GeocoderError from sessionmanager import manager from mysc import event from mysc.thread_utils import call_threaded @@ -47,6 +49,7 @@ from extra import SoundsTutorial from keystrokeEditor import gui as keystrokeEditorGUI log = original_logger.getLogger("gui.main") +geocoder = pygeocoder.Geocoder() class mainFrame(wx.Frame): """ Main class of the Frame. This is the Main Window.""" @@ -90,6 +93,8 @@ class mainFrame(wx.Frame): self.Bind(wx.EVT_MENU, self.unfav, unfav) view = tweet.Append(wx.NewId(), _(u"&Show tweet")) self.Bind(wx.EVT_MENU, self.view, view) + view_coordinates = tweet.Append(wx.NewId(), _(u"View &address")) + self.Bind(wx.EVT_MENU, self.reverse_geocode, view_coordinates) delete = tweet.Append(wx.NewId(), _(u"&Delete")) self.Bind(wx.EVT_MENU, self.delete, delete) @@ -976,6 +981,39 @@ class mainFrame(wx.Frame): def switch_account(self, ev): switchModule.switcher(self) + def reverse_geocode(self, event=None): + try: + if self.db.settings[self.nb.GetCurrentPage().name_buffer][self.nb.GetCurrentPage().list.get_selected()]["coordinates"] != None: + x = self.db.settings[self.nb.GetCurrentPage().name_buffer][self.nb.GetCurrentPage().list.get_selected()]["coordinates"]["coordinates"][0] + y = self.db.settings[self.nb.GetCurrentPage().name_buffer][self.nb.GetCurrentPage().list.get_selected()]["coordinates"]["coordinates"][1] + address = geocoder.reverse_geocode(y, x) + if event == None: output.speak(address[0].__str__().decode("utf-8")) + else: wx.MessageDialog(self, address[0].__str__().decode("utf-8"), _(u"Address"), wx.OK).ShowModal() + else: + output.speak(_(u"There are no coordinates in this tweet")) + except GeocoderError: + output.speak(_(u"There are no results for the coordinates in this tweet")) + except ValueError: + output.speak(_(u"Error decoding coordinates. Try again later.")) + except KeyError: + pass + + def view_reverse_geocode(self, event=None): + try: + if self.db.settings[self.nb.GetCurrentPage().name_buffer][self.nb.GetCurrentPage().list.get_selected()]["coordinates"] != None: + x = self.db.settings[self.nb.GetCurrentPage().name_buffer][self.nb.GetCurrentPage().list.get_selected()]["coordinates"]["coordinates"][0] + y = self.db.settings[self.nb.GetCurrentPage().name_buffer][self.nb.GetCurrentPage().list.get_selected()]["coordinates"]["coordinates"][1] + address = geocoder.reverse_geocode(y, x) + dialogs.message.viewNonTweet(address[0].__str__().decode("utf-8")).ShowModal() + else: + output.speak(_(u"There are no coordinates in this tweet")) + except GeocoderError: + output.speak(_(u"There are no results for the coordinates in this tweet")) + except ValueError: + output.speak(_(u"Error decoding coordinates. Try again later.")) + except KeyError: + pass + ### Close App def Destroy(self): self.sysTray.Destroy() diff --git a/src/sounds/default/geo.mp3 b/src/sounds/default/geo.mp3 new file mode 100644 index 00000000..32d2db81 Binary files /dev/null and b/src/sounds/default/geo.mp3 differ diff --git a/src/twitter/utils.py b/src/twitter/utils.py index c28d9333..fd47ae87 100644 --- a/src/twitter/utils.py +++ b/src/twitter/utils.py @@ -58,6 +58,10 @@ def is_audio(tweet): return True return False +def is_geocoded(tweet): + if tweet.has_key("coordinates") and tweet["coordinates"] != None: + return True + def get_all_mentioned(tweet, config): """ Gets all users that has been mentioned.""" if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"]