Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- More chars in random

- Even less code lines
- Slightly more speed because of importing all bottle module
- New post request router
- New syntax of wildcard filter <tinchy_id>
  • Loading branch information...
commit 5cfa805826788337237e81110d22907200b5ae01 1 parent ee092c3
bender rodriges authored
Showing with 8 additions and 11 deletions.
  1. +8 −11 tinchy.py
19 tinchy.py
View
@@ -1,20 +1,19 @@
-from bottle import route, run, request, redirect
-import random, shelve
+import bottle, random, shelve
def generate_tinchy_id():
- return ''.join(random.sample('abcdefghijklmnopqrstuvwxyz1234567890', 3))
+ return ''.join(random.sample('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890', 3))
@route('/')
def index():
return """
<h1>Get your tinchy URL!</h1>
<form method="post">
- <input type="text" name="url" />
+ <input type="text" name="url" value="http://" />
<input type="submit" value="Make it tinchy!" />
</form>
"""
-@route('/', method='POST')
+@post('/')
def make_tinchy_url():
fatty_url = request.POST.get('url', '')
if fatty_url[:7] == "http://":
@@ -24,18 +23,16 @@ def make_tinchy_url():
tinchy_id = generate_tinchy_id()
storage[tinchy_id] = fatty_url
storage.close()
- tinchy_url = request.url + tinchy_id
- return 'Your tinchy url is: <a href="{0}">{0}</a>'.format(tinchy_url)
+ return 'Your tinchy url is: <a href="%s">%s</a>' % ( request.url + tinchy_id )
return 'Boo, <a href="%s">enter a proper url this time</a>.' % request.url
-@route('/:tinchy_id')
+@route('/<tinchy_id>')
def redirect_to_fatty_url(tinchy_id):
storage = shelve.open("tinchy")
if tinchy_id not in storage:
storage.close()
- return "Nope, this tinchy URL wasn't found."
- fatty_url = storage[tinchy_id]
+ return "Nope, this tinchy URL wasn't found."
storage.close()
- redirect(fatty_url)
+ redirect(storage[tinchy_id])
run(host='localhost', port=8080)
Please sign in to comment.
Something went wrong with that request. Please try again.