Commit a04e4057 authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Properly add expiration timestamps.

parent 07e41f97
......@@ -168,7 +168,7 @@ def register_url( longurl, shorturl, expiration ):
def remove_expired_urls():
mdb, cursor = connect_to_mysql()
today = int(time.time())
sql = """DELETE FROM `%s` WHERE `expiration` > 0 AND `expiration` < %d;"""
sql = """DELETE FROM `%s` WHERE `expiration` > 0 AND `expiration` < %s;"""
cursor.execute( sql, (goconfig.sql_url_table, today) )
mdb.commit()
mdb.close()
......@@ -46,9 +46,13 @@ def application(environ, start_response):
data = library.parse_post_data( data )
# Store parsed user data in these handy variables.
long_url = data["long-url"]
short_url = data["short-url"]
expiration = data["expiration"]
try:
long_url = data["long-url"]
short_url = data["short-url"]
expiration = data["expiration"]
except KeyError:
pass
if not (long_url.startswith("http") or long_url.startswith("ftp")):
long_url = "http://" + long_url
long_url = urllib.unquote( long_url )
......@@ -63,8 +67,10 @@ def application(environ, start_response):
# Parse the expiration date.
today = int(time.time())
if expiration == "never":
end_stamp = -1
if expiration is None:
end_stamp = today
elif expiration == "never":
end_stamp = 0
elif expiration == "month":
end_stamp = today + 2629740
elif expiration == "week":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment