-
Notifications
You must be signed in to change notification settings - Fork 1
/
generic.py
39 lines (36 loc) · 1.22 KB
/
generic.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
# -*- coding:utf8 -*-
import os
import datetime
from store import *
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.api import urlfetch
from functools import wraps
#得到单词的音标
def GetPS(word):
url='http://dict.cn/ws.php?utf8=true&q=%s' % word
try:
explanation=urlfetch.fetch(url).content
except:
return 'None'
if explanation.find(r'<pron>')==-1:
return 'None'
explanation=explanation[explanation.find(r'<pron>')+6:explanation.find(r'</pron>')]
return explanation
#url='http://dict-co.iciba.com/api/dictionary.php?w=%s' % word
#explanation=urlfetch.fetch(url).content
#if explanation.find(r'<ps>')==-1:
# return 'None'
#explanation=explanation[explanation.find(r'<ps>')+4:explanation.find(r'</ps>')]
#return explanation
def requires_admin(method):
@wraps(method)
def wrapper(self, *args, **kwargs):
if not users.get_current_user():
self.redirect(users.create_login_url(self.request.uri))
return
elif not users.is_current_user_admin():
return self.error(403)
else:
return method(self, *args, **kwargs)
return wrapper