This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (50 loc) · 1.6 KB
/
main.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import cgi
import bottle
import pymongo
from pymongo import MongoClient
bottle.debug(True)
client = MongoClient(os.environ['MONGOLAB_URI'])
mongo_db = client.get_default_database()
@bottle.route('/', method="get")
@bottle.view('priorities')
def index():
return dict(name=None)
@bottle.route('/static/<filepath:path>')
def server_static(filepath):
return bottle.static_file(filepath, root='static/')
@bottle.route('/vote/', method="post")
def recieve_txts():
db = mongo_db.priorities
post_response = {
"status": bottle.request.forms.get('status'),
"zip": bottle.request.forms.get('zip'),
"priorities_list": bottle.request.forms.get('priorities_list').split(","),
"years": bottle.request.forms.get('years')
}
insert = db.insert(post_response)
# return repr(insert)
bottle.redirect("/results/")
@bottle.route('/results/', method="get")
@bottle.view('results')
def display_txts():
db = mongo_db.priorities
# return {"results":[1,2,3]}
try:
cursor = db.find()
counts = {}
for result in cursor:
# print repr(result['priorities_list'])
for i, issue in enumerate(result['priorities_list']):
try:
counts[issue] += 1.0/(i+1)
except:
counts[issue] = 1.0/(i+1)
return dict(results=counts)
except Exception as e:
bottle.abort(500, e)
port = int(os.environ.get("PORT", 5000))
bottle.run(server="waitress", host="0.0.0.0", port=port, reloader=True)