Last active
August 24, 2016 08:42
-
-
Save ChrisB9/226dbca05c9cdb7d2e0a7dcb30324154 to your computer and use it in GitHub Desktop.
Python Datetime Url-Listener [Working Example: https://lab.cben.co/python/urlListener.py?year=2015&month=8&day=15]
This file contains hidden or 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 datetime | |
import time | |
import locale | |
import datetime | |
import urlparse | |
import os | |
import cgi | |
import cgitb | |
cgitb.enable() | |
print '''Content-type: text/html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<link rel="stylesheet" type="text/css" href="../../css/style.css" /> | |
</head> | |
<body class="test-data">''' | |
locale.setlocale(locale.LC_TIME, "de_DE") | |
urlstring = os.environ.get('QUERY_STRING') | |
querylist = [{query.split('=')[0]:query.split('=')[1]} if len(query)>0 else "" for query in urlstring.split('&')] | |
todaysData = datetime.datetime.now() | |
workingDate = {'year':todaysData.year, 'month':todaysData.month, 'day':todaysData.day} | |
for args in querylist: | |
if args: | |
workingDate[list(args.keys())[0]] = args[list(args.keys())[0]] | |
try: | |
workingDate = datetime.date(int(workingDate["year"]), int(workingDate["month"]), int(workingDate["day"])) | |
except ValueError: | |
print "Wrong Date-Format!", workingDate | |
else: | |
print workingDate | |
print "</body></html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment