From d371721bf3017bbbd829df8a1f38ba33e832bf74 Mon Sep 17 00:00:00 2001 From: Abhay Rana Date: Thu, 28 Nov 2013 00:47:16 +0530 Subject: [PATCH] Initial commit. --- README.md | 31 +++++++++++++++++++++++++ __main__.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 README.md create mode 100644 __main__.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..f790ecc --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +HackerTray +========== + +HackerTray is a simple [Hacker News](https://news.ycombinator.com/) Linux application +that lets you view top HN stories in your System Tray. It relies on appindicator, so +it is not guaranteed to work on all systems. + +The inspiration for this came from [Hacker Bar](http://hackerbarapp.com), which is +Mac-only. I tried to port it to `node-webkit`, but had to do it in Python instead +because nw doesn't support AppIndicators yet. + +##Features +1. Minimalist Approach to HN +2. Opens links in your default browser +3. Remembers which links you opened +4. Shows Points/Comment count in a simple format +5. + +##To-Do +- Reload data every 5 minutes +- Implement a way to remember which stories have been read +- Ideally app-memory should be persistent (save on disk) +- Auto Start +- Convert to a Python Module +- Add a menu separator between news and preferences. + +##Author Information +- Abhay Rana + +##Licence +Licenced under the MIT Licence \ No newline at end of file diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..190816f --- /dev/null +++ b/__main__.py @@ -0,0 +1,67 @@ +#!/usr/bin/python + +import pygtk +pygtk.require('2.0') +import gtk +import appindicator +import requests +import webbrowser + +class HackerNewsApp: + def __init__(self): + self.ind = appindicator.Indicator ("Hacker Tray", "hacker-tray", appindicator.CATEGORY_APPLICATION_STATUS) + self.ind.set_status (appindicator.STATUS_ACTIVE) + self.ind.set_label("Y") + + # create a menu + self.menu = gtk.Menu() + + # create items for the menu - labels, checkboxes, radio buttons and images are supported: + btnRefresh = gtk.MenuItem("Refresh This") + btnRefresh.show() + btnRefresh.connect("activate", self.refresh) + self.menu.append(btnRefresh) + + btnQuit = gtk.MenuItem("Quit") + btnQuit.show() + btnQuit.connect("activate", self.quit) + self.menu.append(btnQuit) + + self.menu.show() + + self.ind.set_menu(self.menu) + self.refresh() + + def quit(self, widget, data=None): + gtk.main_quit() + + def open(self, widget, data=None): + webbrowser.open(widget.url) + + def addItem(self, item): + i = gtk.CheckMenuItem("("+str(item['points']).zfill(3)+"/"+str(item['comments_count']).zfill(3)+") "+item['title']) + i.url = item['url'] + i.connect('activate', self.open) + self.menu.prepend(i) + i.show() + + def refresh(self, widget=None, data=None): + self.data = reversed(getHomePage()[0:15]); + for i in self.menu.get_children(): + if(i.__class__.__name__=="CheckMenuItem"): + self.menu.remove(i) + for i in self.data: + self.addItem(i) + + +def getHomePage(): + r = requests.get('https://node-hnapi.herokuapp.com/news') + return r.json() + +def main(): + gtk.main() + return 0 + +if __name__ == "__main__": + indicator = HackerNewsApp() + main() \ No newline at end of file