-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
83 lines (73 loc) · 2.07 KB
/
helpers.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
79
80
81
82
83
# coding: utf-8
import os
import re
from hashlib import md5
import time
import config
config = config.rec()
def getDay(timestamp):
FORY = '%d'
os.environ["TZ"] = config.default_timezone
time.tzset()
str = time.strftime(FORY, time.localtime(timestamp))
return str
def getMonth(timestamp):
FORY = '%b'
os.environ["TZ"] = config.default_timezone
time.tzset()
str = time.strftime(FORY, time.localtime(timestamp))
return str
def formatDate(timestamp):
FORY = '%Y-%m-%d @ %H:%M'
FORM = '%m-%d @ %H:%M'
FORH = '%H:%M'
os.environ["TZ"] = config.default_timezone
time.tzset()
rtime = time.strftime(FORM, time.localtime(timestamp))
htime = time.strftime(FORH, time.localtime(timestamp))
now = int(time.time())
t = now - timestamp
if t < 60:
str = '刚刚'
elif t < 60 * 60:
min = t / 60
str = '%d 分钟前' % min
elif t < 60 * 60 * 24:
h = t / (60 * 60)
str = '%d 小时前 %s' % (h,htime)
elif t < 60 * 60 * 24 * 3:
d = t / (60 * 60 * 24)
if d == 1:
str = '昨天 ' + rtime
else:
str = '前天 ' + rtime
else:
str = time.strftime(FORY, time.localtime(timestamp))
return str
def formatDate2(timestamp):
FORY = '%Y-%m-%d @ %H:%M'
os.environ["TZ"] = config.default_timezone
time.tzset()
str = time.strftime(FORY, time.localtime(timestamp))
return str
def getAvatar(email, size=96):
return \
'http://gravatar.com/avatar/%s?d=identicon&s=%d&d=http://feather.im/static/img/gravatar.png' \
% (md5(email.strip().lower().encode('utf-8')).hexdigest(), size)
def showPost(content, pid=1):
end = content.find("<more>")
if end != -1:
readmore = '<a class="readmore" href="/post/%d">>> 阅读更多</a>' % (int(pid))
return content[0:end] + readmore
else:
return content
def formatText(text):
floor = ur'#(\d+)楼\s'
for match in re.finditer(floor, text):
url = match.group(1)
floor = match.group(0)
nurl = '<a class="toreply" href="#;">#<span class="tofloor">%s</span>楼 </a>' % (url)
text = text.replace(floor, nurl)
return text
def replyContent(text):
return text[0:26]