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
a04e4057
Commit
a04e4057
authored
Oct 06, 2013
by
Jean Michel Rouly
Browse files
Properly add expiration timestamps.
parent
07e41f97
Changes
2
Hide whitespace changes
Inline
Side-by-side
wsgi/library.py
View file @
a04e4057
...
...
@@ -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
()
wsgi/url-register.py
View file @
a04e4057
...
...
@@ -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"
:
...
...
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