forked from ShinNoNoir/likelines-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
72 lines (52 loc) · 1.52 KB
/
api.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
import web
import time
def Connection():
import pymongo
return pymongo.Connection(web.DOTCLOUD_DATA_MONGODB_URL)
def UserId():
import uuid
str(uuid.uuid4())
user_id = web.cookies(user_id=None).user_id
if user_id is None:
user_id = str(uuid.uuid4())
web.setcookie('user_id', user_id, 31556926)
return user_id
class Heatmap:
"""
/heatmap?video=<url>&[getkey=1|0]
Returns:
{
"heatmap": <heatmap>,
"interaction_key": <interaction_key>
}
"""
def GET(self, video, getkey=False):
# TODO: URL normalizer?
conn = Connection()
likes_db = conn.likes
played_fragments = conn.played_fragments
# TODO: "schema"?
# TODO: users?
for like in likes_db.find({'video': video}):
pass
res = {}
res['heatmap'] = []
if getkey:
interaction_keys_db = conn.interaction_keys
res['key'] = getkey
return res
class Echo:
def GET(self, **kwargs):
res = dict(kwargs)
try:
conn = Connection()
db = conn.test_db
res['db.foos'] = foos = []
for foo in db.foos.find():
del foo['_id']
foos.append(foo)
res['user_id'] = UserId()
except:
import traceback
res['exc'] = traceback.format_exc()
return res