def __init__(self, cache_path=None): self.cache_path = cache_path if cache_path is None: self.config = Config() self.cache_path = self.config.parser.get('settings', 'cache') self.cache_age = int(self.config.parser.get('settings', 'cache_age')) self.extra_page = int(self.config.parser.get('settings', 'extra_page')) self.api = HackerNewsAPI() if not os.path.exists(self.cache_path): self.refresh()
def refreshKarma(self): """ Gets the karma count of a user from the source of their 'user' page. """ hn = HackerNewsAPI() source = hn.getSource(self.userPageURL) karmaStart = source.find('<td valign=top>karma:</td><td>') + 30 karmaEnd = source.find('</td>', karmaStart) karma = source[karmaStart:karmaEnd] if karma is not '': self.karma = int(karma) else: raise HNException("Error getting karma for user " + self.name)
(widget, foo) = self._listbox.get_focus() (text, foo) = widget.get_text() self.selected = text[1:] # Get rid of the leading space... else: return self._listbox.keypress(size, key) ########NEW FILE######## __FILENAME__ = get_comments #!/usr/bin/env python # -*- coding: utf-8 -*- import os import json from hnapi import HackerNewsAPI hn = HackerNewsAPI() stories = hn.getTopStories() story = stories[0] if not os.path.exists('comments.data'): comments = story.getComments() open('comments.data', 'w').write(json.dumps(comments)) else: comments = json.load(open('comments.data')) ########NEW FILE######## __FILENAME__ = treesample #!/usr/bin/python # # Trivial data browser # This version: