Skip to content

Instantly share code, notes, and snippets.

@lobodin
Created December 23, 2010 14:45
Show Gist options
  • Save lobodin/753065 to your computer and use it in GitHub Desktop.
Save lobodin/753065 to your computer and use it in GitHub Desktop.
from urlparse import parse_qs
from datetime import datetime
def dates(environ, start_response):
dates = parse_qs(environ['QUERY_STRING'])
get_date = lambda d: datetime.strptime(dates[d][0], '%m/%d/%Y')
try:
start = get_date('start')
end = get_date('end')
status = '200 OK'
except:
status = '400 Bad Request'
start_response(status, [('Content-Type', 'text/html')])
return [str((end - start).days)] if status == '200 OK' else ''
if __name__ == '__main__':
from wsgiref.simple_server import make_server
srv = make_server('localhost', 8080, dates)
srv.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment