forked from yetone/collipa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensions.py
47 lines (40 loc) · 1.1 KB
/
extensions.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
# coding: utf-8
import re
#import misaka
import config
import memcache
import redis
import cPickle as pickle
config = config.rec()
mc = memcache.Client(['127.0.0.1:11211'], debug=1)
rd = redis.StrictRedis(host='127.0.0.1', port=config.rd_port, db=0)
'''
def md(text):
text = img_convert(text)
return misaka.html(text, extensions=misaka.EXT_FENCED_CODE |
misaka.EXT_AUTOLINK, render_flags=misaka.HTML_SKIP_HTML)
'''
def img_convert(text):
img_url = ur'http[s]:\/\/[^\s\"]*\.(jpg|jpeg|png|bmp|gif)'
for match in re.finditer(img_url, text):
url = match.group(0)
img_tag = '![](%s)' % url
text = text.replace(url, img_tag)
return text
def pk(name, value=None):
if value:
try:
f = file('/dev/shm/' + name + '.pkl', 'wb')
pickle.dump(value, f, 2)
f.close()
return True
except Exception, e:
print e
return False
try:
f = file('/dev/shm/' + name + '.pkl', 'rb')
value = pickle.load(f)
f.close()
return value
except:
return None