Created
December 23, 2010 14:45
-
-
Save lobodin/753065 to your computer and use it in GitHub Desktop.
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
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