Python API for Hacker News
That library is in many ways deprecated and broken: At first, it uses only old-style classes because it doesn't inherits object explicitly. Furthermore, it uses print in a method; it would be more "Pythonic" to return a str object, which was formatted using str.format.
I think the future is Python 3, and new implementations in Python 2 syntax are simply unneccessary. I would suggest the usage of Python-3-style syntax, which is also valid in Python 2.7 (which isn't hard).
I tried building a REST API once for a challenge if anyone is interested: https://github.com/mapleoin/newhackers
Nice effort. Just a few remarks:
- You should certainly use Requests http://docs.python-requests.org/en/latest/
- The Story class seems somewhat redundant. You could possibly use collections.namedtuple as a container for properties or simply a dictionary. The print_story method could just be the __str__ special method.
- JSON output would be useful.
Does it use https://www.hnsearch.com/api ?
I think screen scrapping is not allowed by HN. Few tries with these APIs might get your IP banned!
I don't get why you're using a try except block for the num_comments variable. You shouldn't be casting to an int if it doesn't have the attribute.
It's silly to use BeautifulSoup to parse the page when you could use a simple RegEx:
<td class=\"title\"><a href=\"(.?)\"(.?)>(.?)</a>(.?)</td>