-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.fcgi.fork
More file actions
executable file
·138 lines (127 loc) · 6.97 KB
/
code.fcgi.fork
File metadata and controls
executable file
·138 lines (127 loc) · 6.97 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
#-*- encoding:utf-8 -*-
import web
import time
import math
import simplejson
from pymongo import Connection
import base64
import os
import signal
signal.signal(signal.SIGCHLD,signal.SIG_IGN)
urls = ('/home/(.*)','guests',
'/hd/(.*)','active',)
app = web.application(urls,globals())
def gettime(ts):
if ts < 2 :
return '刚刚'
else:
periods = (('年',31556926),('月',2629744),('周',604800),('天',86400),('小时',3600),('分钟',60),('秒钟',1))
for q in periods:
x = int(math.floor(ts/q[1]))
ts -= x*q[1]
if x > 0:
st = str(x) + q[0]
break;
return st+'前'
def mongo_connect(database = 'guest',connection = 'photo',host = 'localhost',port = 27017):
conn = Connection(host,port)
return conn[database][connection]
class guests:
def GET(self,nc):
qs = web.input(obj='photo',objid=0,guest_uid=0,guest_ts=time.time(),jsoncallback = '1')
obj = str(qs.obj)
pos = (obj == 'user') and 9 or 15
now = time.time()
conn = mongo_connect(connection = str(obj))
objid = int(qs.objid)
if qs.guest_uid:
ds = conn.find_one({'objectid':objid})
guest_nc = base64.decodestring(nc).decode('utf-8')
if not ds:
html_m = '<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/%s"><img src="http://avatar.hunantv.com/%d/%s_48_48.jpg?r="></a></dt><dd class="name"> <a href="/home/profile/index/%s">%s</a></dd><dd class="time">%s</dd></dl></div><div class="fix"></div>'%(qs.guest_uid,int(qs.guest_uid)%255,qs.guest_uid,qs.guest_uid,guest_nc,'刚刚'.decode('utf8'))
ds = {'objectid':objid,qs.guest_uid:{'nc':guest_nc,'ts':int(qs.guest_ts)}}
try:
pid = os.fork()
except:
pass
if not pid:
conn.insert(ds)
os._exit(0)
else:
return qs.jsoncallback+'('+simplejson.dumps({'msg':html_m,'err':0})+');'
else:
del ds['_id']
del ds['objectid']
ds[qs.guest_uid] = {'nc':guest_nc,'ts':int(qs.guest_ts)}
seq = sorted(ds.items(), key=lambda x: x[1]['ts'],reverse = True)[0:pos]
html_m = ''.join(map(lambda x:'<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/%s"><img src="http://avatar.hunantv.com/%d/%s_48_48.jpg?r="></a></dt><dd class="name"> <a href="/home/profile/index/%s">%s</a></dd><dd class="time">%s</dd></dl></div>'%(x[0],int(x[0])%255,x[0],x[0],x[1]['nc'],gettime(now-x[1]['ts']).decode('utf8')),seq))
main = {'objectid':objid}
main.update(ds)
try:
pid = os.fork()
except:
pass
if not pid:
conn.update({'objectid':objid},main)
os._exit(0)
else:
return qs.jsoncallback+'('+simplejson.dumps({'msg':html_m+'<div class="fix"></div>','err':0})+');'
else:
ds = conn.find_one({'objectid':objid})
if not ds: return qs.jsoncallback+'('+simplejson.dumps({'msg':'<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/0"><img src="http://avatar.hunantv.com/0/1_48_48.jpg?r="></a></dt><dd class="name"> <a href="#">无名芒果</a></dd><dd class="time">此刻哦</dd></dl></div><div class="fix"></div>','err':0})+');'
del ds['_id']
del ds['objectid']
seq = sorted(ds.items(), key=lambda x: x[1]['ts'],reverse = True)[0:14]
html_m = ''.join(map(lambda x:'<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/%s"><img src="http://avatar.hunantv.com/%d/%s_48_48.jpg?r="></a></dt><dd class="name"> <a href="/home/profile/index/%s">%s</a></dd><dd class="time">%s</dd></dl></div>'%(x[0],int(x[0])%255,x[0],x[0],x[1]['nc'],gettime(now-x[1]['ts']).decode('utf8')),seq))
return qs.jsoncallback+'('+simplejson.dumps({'msg':html_m+'<div class="fix"></div>','err':0})+');'
class active:
def GET(self,nc):
qs = web.input(obj='active',objid=0,guest_uid=0,guest_ts=time.time(),jsoncallback = '1',limit = 50)
obj = str(qs.obj)
now = time.time()
conn = mongo_connect(connection = str(obj))
objid = int(qs.objid)
if qs.guest_uid:
ds = conn.find_one({'objectid':objid})
guest_nc = base64.decodestring(nc).decode('utf-8')
if not ds:
html_m = '<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/%s"><img src="http://avatar.hunantv.com/%d/%s_48_48.jpg?r="></a></dt><dd class="name"> <a href="/home/profile/index/%s">%s</a></dd><dd class="time">%s</dd></dl></div><div class="fix"></div>'%(qs.guest_uid,int(qs.guest_uid)%255,qs.guest_uid,qs.guest_uid,guest_nc,'刚刚'.decode('utf8'))
ds = {'objectid':objid,qs.guest_uid:{'nc':guest_nc,'ts':int(qs.guest_ts)}}
try:
pid = os.fork()
except:
pass
if not pid:
conn.insert(ds)
os._exit(0)
else:
return qs.jsoncallback+'('+simplejson.dumps({'msg':html_m,'err':0})+');'
else:
del ds['_id']
del ds['objectid']
ds[qs.guest_uid] = {'nc':guest_nc,'ts':int(qs.guest_ts)}
seq = sorted(ds.items(), key=lambda x: x[1]['ts'],reverse = True)[0:int(qs.limit)]
html_m = ''.join(map(lambda x:'<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/%s"><img src="http://avatar.hunantv.com/%d/%s_48_48.jpg?r="></a></dt><dd class="name"> <a href="/home/profile/index/%s">%s</a></dd><dd class="time">%s</dd></dl></div>'%(x[0],int(x[0])%255,x[0],x[0],x[1]['nc'],gettime(now-x[1]['ts']).decode('utf8')),seq))
main = {'objectid':objid}
main.update(ds)
try:
pid = os.fork()
except:
pass
if not pid:
conn.update({'objectid':objid},main)
os._exit(0)
else:
return qs.jsoncallback+'('+simplejson.dumps({'msg':html_m+'<div class="fix"></div>','err':0})+');'
else:
ds = conn.find_one({'objectid':objid})
if not ds: return qs.jsoncallback+'('+simplejson.dumps({'msg':'<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/0"><img src="http://avatar.hunantv.com/0/1_48_48.jpg?r="></a></dt><dd class="name"> <a href="#">无名芒果</a></dd><dd class="time">此刻哦</dd></dl></div><div class="fix"></div>','err':0})+');'
del ds['_id']
del ds['objectid']
seq = sorted(ds.items(), key=lambda x: x[1]['ts'],reverse = True)[0:14]
html_m = ''.join(map(lambda x:'<div class="item"><dl><dt class="png-fix"><a href="/home/profile/index/%s"><img src="http://avatar.hunantv.com/%d/%s_48_48.jpg?r="></a></dt><dd class="name"> <a href="/home/profile/index/%s">%s</a></dd><dd class="time">%s</dd></dl></div>'%(x[0],int(x[0])%255,x[0],x[0],x[1]['nc'],gettime(now-x[1]['ts']).decode('utf8')),seq))
return qs.jsoncallback+'('+simplejson.dumps({'msg':html_m+'<div class="fix"></div>','err':0})+');'
if __name__ == "__main__":
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
app.run()