Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Including threading, cache, and rudimentary web front end.

Edited for asyncronous feedback.

Used as so: http://localhost:9242/http://tinyurl.com/unicycles

  import urllib2, cherrypy.wsgiserver
  cache = {}
  def app(environ, start_response):
    start_response('200 OK', [('Content-type','text/plain')])
    url = environ['PATH_INFO'].lstrip('/')
    yield 'Looking up: ' + url + '...'
    try:
      result = cache.get(url)
      if result is None:
        result = urllib2.urlopen(url).geturl()
        cache[url] = result
    except urllib2.HTTPError:
      result = "URL Doesn't exist"
    except ValueError:
      result = "Invalid Url"
    yield result
  
  cherrypy.wsgiserver.CherryPyWSGIServer(('127.0.0.1', 9242), app).start()


Very nice. Having real threads is convenient.


Haha.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: