Initial commit.

This commit is contained in:
Abhay Rana 2013-11-28 00:47:16 +05:30
commit d371721bf3
2 changed files with 98 additions and 0 deletions

31
README.md Normal file
View File

@ -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 <me@captnemo.in>
##Licence
Licenced under the MIT Licence

67
__main__.py Normal file
View File

@ -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()