Created
June 17, 2010 16:42
-
-
Save qoelet/442374 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# serving of squash | |
from bottle import route, run, send_file, abort, request, response, redirect, template | |
from squash import * | |
from settings import * | |
# Squash homepage, with form for generating short urls | |
@route('/') | |
def homepage(): | |
return template('squashit.tpl',title='Shorten your URLs with Squash!') | |
# Static files | |
@route('/static/:filename') | |
def static_file(filename): | |
send_file(filename, root=MEDIA_ROOT) | |
# Gets long url and returns shortened url | |
@route('/shorten/', method='POST') | |
def squashurl(): | |
if 'url' in request.POST: | |
url = request.POST['url'] | |
s = Squash() | |
shortened_url = s.sendto_lightcloud(url) | |
return template('squashed.tpl',title='Shorten your URLs with Squash!',result=(MYDOMAIN+shortened_url)) | |
# Redirects to url | |
@route('/:id') | |
def transfer(id): | |
s = Squash() | |
fullurl = s.getfrom_lightcloud(id) | |
if fullurl is not None: | |
redirect(fullurl) | |
else: | |
return "Invalid id." | |
run(host='localhost', port=MYPORT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment