Skip to content

Instantly share code, notes, and snippets.

Created June 22, 2013 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5838675 to your computer and use it in GitHub Desktop.
Save anonymous/5838675 to your computer and use it in GitHub Desktop.
from bottle import Bottle, route, run, template, static_file, get, post, request, response
from passlib.hash import sha256_crypt
import MySQLdb as mdb
import time
import re
@get('/enviar')
def enviar_letra():
return template('enviar_letra.tpl')
@post('/enviar')
def guardar_letra():
titulo = request.forms.get('titulo').capitalize() # Gets the song title from the form
artista = request.forms.get('artista') # Gets the artist
letra = request.forms.get('letra') # Gets the lyrics
fecha_envio = time.strftime('%Y-%m-%d %H:%M:%S') # Date the lyrics were sent
titulo = re.sub('[^\w|!|\s|\.|,]', '', titulo) # I delete every character except: words, exclamation, spaces, dots, commas
url = titulo + "-" + artista # concatenate the song's title and the artist name to make a nice url
url = re.sub('\W+|_', '-', url).lower() # lower all the characters from the url
url = url.strip("-") # strips "-" at the beginning and the end
letra = letra.replace("\n", "<br>") # replaces \n from the lyrics text area with <br>
data = { "titulo": titulo, "artista": artista, "letra": letra, "url": url, "Fecha_envio": fecha_envio } # song dictionary
return template('prueba.tpl', letra = data) # loads prueba.tpl template and send "data" dictionary as "letra" (letra is lyric in spanish)
run(host='localhost', port=8080, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment