-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
78 lines (61 loc) · 1.72 KB
/
app.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
71
72
73
74
75
76
77
78
'''
Back end for GeoBoards project
'''
#imports
from bottle import Bottle, request, run
from db import DB
from posts import Post, Location
from data_fixer import clean_lat,clean_long
from data_fixer import dejsonify_posts
import json
import json
#########################################################
api = Bottle()
database = DB()
#returns posts
@api.get('/getposts/<lat>/<long>')
def get_posts(lat,long):
lat = clean_lat(lat)
long = clean_long(long)
print str(lat) + ' ' + str(long)
#should return the posts at lat,long
posts_ = database.find_at(lat,long)
posts = []
for post in posts_:
p = post.to_dict()
posts.append(p)
return_dict = {}
return_dict['posts'] = posts
return_dict['latitude'] = lat
return_dict['longitude'] = long
return json.dumps(return_dict)
@api.post('/newpost')
def new_post():
#saves new post to db
print request
post_dict = request.json
#post_dict = dejsonify_posts(post_json)
#id,location,body,owner_disp,owner_id
lat = post_dict['location']['latitude']
long = post_dict['location']['longitude']
alt = post_dict['location']['altitude']
timestamp = post_dict['location']['timestamp']
post = Post(database.gen_id(), \
Location(lat,long,alt,timestamp), \
post_dict['postContent'], \
post_dict['dispName'], \
post_dict['userID'])
database.add(post.id,post)
return 'added!'
@api.get('/dumpdb')
def dump():
database.dump()
return 'k'
#not yet functional
@api.get('/user/<user>')
def get_user(user):
usr = database.get_user(user)
@api.delete('post/<id>')
def del_post(id):
database.rm(id)
run(api, host='192.241.134.224',port=80)