Skip to content

Instantly share code, notes, and snippets.

@brettcvz
Last active December 11, 2015 11:48
Show Gist options
  • Save brettcvz/4596472 to your computer and use it in GitHub Desktop.
Save brettcvz/4596472 to your computer and use it in GitHub Desktop.
Simple webserver that takes in a hn story id and returns the points of the story. Has no error handling
import web
from pyquery import PyQuery as pq
import re
urls = (
'/(.*)', 'hn'
)
app = web.application(urls, globals())
class hn:
def GET(self, story_id):
if not story_id:
return "No story found"
story = int(story_id)
d = pq(url="http://news.ycombinator.com/item?id=%d" % (story))
score = d("#score_%d" % story).text()
return "^%s$" % re.search(r"(\d+)", score).group(1)
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment