from sanic import Sanic, response
from sanic.response import json, text
from sanic.exceptions import NotFound 
from jinja2 import Environment, FileSystemLoader
import re
import ipdb
import sys
import traceback
import json
import datetime
from email.utils import format_datetime
from urllib.parse import urlparse
import base64
file_loader = FileSystemLoader('templates')
env = Environment(loader=file_loader)
app = Sanic('Bitrhythm')


@app.exception(NotFound)
async def ignore_404s(request, exception):
    return text('Yep, I totally found the page ' + request.url)


@app.route('/song/<name>')
async def get_index(request, name):
    template = env.get_template('index.html')
    return response.html(template.render({'data': name}))


@app.route('/')
async def get_index(request):
    template = env.get_template('index.html')
    return response.html(template.render({'data': ''}))


@app.route('/issue')
async def get_index(request):
    template = env.get_template('page.html')
    return response.html(template.render())


app.static('/', './public')
if __name__ == '__main__':
    import sys
    app.run(host='0.0.0.0', port=8015)

