Skip to content

Commit

Permalink
make the code even shorter, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tnm committed Jul 18, 2011
1 parent d725bd6 commit 7b592bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -6,14 +6,17 @@ Simple-as-possible, personal link shortener with Bottle and Redis. Uses Redis' I
Requires:

* [Redis](http://github.com/antirez/redis "Redis")

* [Bottle](http://github.com/defnull/bottle "Bottle")

* [redis-py](http://github.com/andymccurdy/redis-py "redis-py")

telstar is directly inspired by Dave Jeffery's tinchy, Leah Culver's tinytinyurl, and also by Cake's song Daria (which was playing in the couple of minutes when telstar was written).

author: Ted Nyman
to run
---------

With the deps installed and a running redis-server on localhost, `python telstar.py` will start the telstar web interface on `localhost`. Point your browser
to `http://localhost:8080/` and start shortening links.

author: Ted Nyman
license: MIT

16 changes: 7 additions & 9 deletions telstar.py
Expand Up @@ -41,15 +41,13 @@ def index():
@route('/', method='POST')
def make_small_url():
big_url = request.POST.get('url', '').strip()
if big_url[:7] == "http://":
small_id = r.incr("url:all")
small_id = str(small_id)
set_big_url = r.set(big_url, small_id)
set_small_url = r.set(small_id, big_url)
small_url = BASEURL + small_id
return 'Your small url is: <a href="{0}">{0}</a>'.format(small_url)
else:
return 'Dude, that is not a legit URL. It needs to start with <strong>http:// </strong><a href="/">Get real.</a>'
small_id = str(r.incr("url:all"))

set_big_url = r.set(big_url, small_id)
set_small_url = r.set(small_id, big_url)

small_url = BASEURL + small_id
return 'Your small url is: <a href="{0}">{0}</a>'.format(small_url)

@route('/:small_id')
def redirect_to_big_url(small_id):
Expand Down

0 comments on commit 7b592bb

Please sign in to comment.