Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
07e41f97
Commit
07e41f97
authored
Oct 06, 2013
by
Jean Michel Rouly
Browse files
Remove old URLs when redirecting.
parent
096d4aac
Changes
2
Hide whitespace changes
Inline
Side-by-side
wsgi/library.py
View file @
07e41f97
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
()
wsgi/redir.py
View file @
07e41f97
...
...
@@ -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>"
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment