Last active
December 11, 2015 11:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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