summaryrefslogtreecommitdiff
path: root/app.py
blob: e379cb1d8069b364e9ff5d5df8cef10ad3687689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import os
import random
import requests
import string

from bottle import post, route, request, run, static_file, template

CLOUDANT_BASE = 'https://pinkyswear.cloudant.com/pinkyswear/'
CLOUDANT_AUTH = ('pinkyswear', 'abc123')

@route('/')
def index(name='home'):
    return template('index.html', sig=None)

@route('/s/:id')
def sig(id='home'):
    url = CLOUDANT_BASE + id
    r = requests.get(url, auth=CLOUDANT_AUTH)
    sig = json.loads(r.content)['s']
    return template('index.html', sig=sig)

@post('/s')
def sig(id='home'):
    data = json.dumps({ 's' : request.POST['output'] })
    url = CLOUDANT_BASE
    headers = { 'content-type' : 'application/json' }
    r = requests.post(url, auth=CLOUDANT_AUTH, data=data, headers=headers)
    return r.content

run(host='localhost', port=8000)