-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
43 lines (36 loc) · 1.2 KB
/
handler.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
#-*- coding:utf-8 -*-
from flask import request
from flask import jsonify
from pymongo import MongoClient
import json
client = MongoClient('localhost',27017)
db = client.test
events = db.events
def save_event():
print('enter save_event data'+request.data)
data = {
"name":request.form.get('name', 'name'),
"avatar":request.form.get('avatar', 'avatar'),
"timestamp": request.form.get('timestamp', 'timestamp'),
"msg": request.form.get('msg', 'msg'),
"location": request.form.get('location', 'location'),
}
print(data)
events.insert(data)
print('exit save_event')
return jsonify(code=200, msg='success')
def get_events():
print('enter get_events')
datas = events.find({"name":request.args.get('name')})
array = []
for info in datas:
item = {}
item['name'] = info.get('name')
item['avatar'] = info.get('avatar')
item['timestamp'] = info.get('timestamp')
item['msg'] = info.get('msg')
item['location'] = info.get('location')
array.append(item)
print(item)
print('exit get_events')
return jsonify(code=200, msg='success', data=json.dumps(array, ensure_ascii=False))