From 9017cddbcef47b7c12a1df6e1e24e50211afbefe Mon Sep 17 00:00:00 2001 From: Andrew Davidson Date: Thu, 11 Dec 2014 21:56:10 -0500 Subject: [PATCH] commit to push to gitlab --- brain.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/brain.py b/brain.py index d5e9016..737b8e4 100644 --- a/brain.py +++ b/brain.py @@ -4,7 +4,9 @@ import bottle from bottle import default_app, get, post, route, run, request, template, static_file, redirect from os.path import isdir from string import lower, split -from urllib import unquote +import string +from urllib import unquote, urlopen +from urlparse import urlparse import shutil from datetime import datetime import re @@ -12,10 +14,6 @@ import Image from markdown2 import markdown import MySQLdb from contextlib import closing -from urllib import urlopen -from urlparse import urlparse -from contextlib import closing -import string import random @@ -84,6 +82,13 @@ def mkpass(size=10): return string.join([random.choice(validChars) for x in range(size)],"") +def mkshort(size=4): + validChars = string.ascii_letters + string.digits + validChars = validChars.strip("oO01l") + + return string.join([random.choice(validChars) for x in range(size)],"") + + def get_generated(domain): get = 'SELECT password FROM secrets_gen WHERE base_url LIKE "%'+get_domain(domain)+'%" LIMIT 1' create = 'INSERT INTO secrets_gen (base_url, password) VALUES ("'+get_domain(domain)+'","'+mkpass()+'")' @@ -717,10 +722,9 @@ def mkdir(): # Let's build in the url shortening functionality. -@route('/short/') -@route('/short/') -@route('/short') +@get('/short/') def short(short = ''): + body = [] if short: query = 'SELECT url,public FROM short WHERE `key` = "'+short+'" LIMIT 1;' @@ -729,17 +733,20 @@ def short(short = ''): if url: redirect(url[0]) - else: - body = ['Short url "'+short+'" does not exist.'] - return template('templates/public', content='\n'.join(body),\ - title='Error') + - else: - body = ['You must provide a short url.'] - return template('templates/public', content='\n'.join(body),\ - title='Error') +@get('/short/') +@get('/short') +def mkshort(short = ''): + body = [] + body.append("

Create Shortened URL.

") + body.append('
') + body.append('') + body.append('
') + return template('templates/public', content='\n'.join(body),\ + title='Create Shortened URL' + short) # Let's make a place to store my secrets