Commit 07e41f97 authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Remove old URLs when redirecting.

parent 096d4aac
import random
import time
import math
import site
import MySQLdb
......@@ -161,3 +162,13 @@ def register_url( longurl, shorturl, expiration ):
cursor.execute( sql, (goconfig.sql_url_table, longurl, shorturl, expiration) )
mdb.commit()
mdb.close()
# Removes any expired urls in the url table.
def remove_expired_urls():
mdb, cursor = connect_to_mysql()
today = int(time.time())
sql = """DELETE FROM `%s` WHERE `expiration` > 0 AND `expiration` < %d;"""
cursor.execute( sql, (goconfig.sql_url_table, today) )
mdb.commit()
mdb.close()
......@@ -6,6 +6,8 @@ import library
import goconfig
def application(environ, start_response):
# First things first - clear any old URL entries.
library.remove_expired_urls()
# Construct the default body, along with its header/footer wrapper.
body = ["<p>Nothing here.</p>"]
......
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