本文整理汇总了Python中main.app.config方法的典型用法代码示例。如果您正苦于以下问题:Python app.config方法的具体用法?Python app.config怎么用?Python app.config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类main.app
的用法示例。
在下文中一共展示了app.config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: push_important_news
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def push_important_news():
key = request.values.get('key')
news = ndb.Key(urlsafe=key).get()
form_fields = {
"token": app.config["PUSHOVER_APP_KEY"],
"user": app.config["PUSHOVER_USER_KEY"],
"message": news.summary.encode("utf-8"),
"url": news.link.encode("utf-8"),
"url_title": u"点击访问正文".encode("utf-8"),
"title": news.title.encode("utf-8"),
}
form_data = urllib.urlencode(form_fields)
urlfetch.fetch(url=app.config["PUSH_OVER_URL"],
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'},
follow_redirects=False,
validate_certificate=False)
return "Done", 200
示例2: signin_oauth
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def signin_oauth(oauth_app, scheme=None):
"""Attemps to sign in via given oauth_app. If successfull it will redirect to
appropriate url. E.g. if signing via github it will call github_authorized
as callback function
Args:
oauth_app (OAuth): Flask Oauth app
scheme (string): http or https to use in callback url
"""
if scheme is None:
scheme = 'https' if config.PRODUCTION else 'http'
try:
flask.session.pop('oauth_token', None)
save_request_params()
return oauth_app.authorize(callback=flask.url_for(
'%s_authorized' % oauth_app.name, _external=True, _scheme=scheme
))
except oauth.OAuthException:
flask.flash('Something went wrong with sign in. Please try again.')
return flask.redirect(flask.url_for('index'))
示例3: express_shipment_tracking
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def express_shipment_tracking():
"""快递查询"""
if message.type == 'text':
timeout = int(message.time) - int(get_user_last_interact_time(openid))
# 超过一段时间,退出模式
if timeout > 15 * 60:
set_user_state(openid, 'default')
content = app.config['EXPRESS_TIMEOUT_TEXT'] + \
app.config['HELP_TEXT']
return wechat.response_text(content)
else:
# 放入队列任务执行,异步回复
express.get_tracking_info.delay(openid, message.content)
# 立即返回
return 'success'
else:
if message.ScanCodeInfo[0]['ScanType'] == 'barcode':
# 读取条形码扫描的单号
num = message.ScanCodeInfo[0]['ScanResult'].split(",", 1)[1]
# 异步查询
express.get_tracking_info.delay(openid, num)
return 'success'
else:
return wechat.response_text('识别错误,请扫描快递条形码')
示例4: url2parser
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def url2parser(url):
try:
result = urlfetch.fetch(url, headers={'User-Agent': app.config['USER_AGENT']}, deadline=app.config['DEADLINE'])
if result.status_code == 200:
parser = feedparser.parse(result.content)
return parser
else:
return None
except:
return None
示例5: launch_fetch
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def launch_fetch():
feeds = get_quarterly_feed_key()
now = datetime.now(tz=app.config["TIME_ZONE"])
if now.minute / 15 == 3:
feeds += get_hourly_feed_key()
if now.hour == 9 and now.minute / 15 == 1:
feeds += get_daily_feed_key()
for feed in feeds:
taskqueue.add(queue_name='fetch-queue',
url=url_for("fetch_one_feed"),
method='POST',
params={"key": feed.urlsafe()}
)
return "Done", 200
示例6: collect_keyword_for_one_news
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def collect_keyword_for_one_news():
user_key_word = get_pure_keyword()
key = request.values.get('key')
news = ndb.Key(urlsafe=key).get()
form_fields = {
"text": news.summary.encode("utf-8"),
"topK": app.config["TOP_KEYWORD"],
"withWeight": 0
}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=app.config["JIEBA_API"],
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'},
follow_redirects=False)
json_content = json.loads(result.content)
key_words = json_content["result"]
del news.key_word[:]
news.key_word = key_words
tmp = [val for val in key_words if val in user_key_word]
if tmp:
news.important = True
if tmp and app.config["PUSHOVER"]:
taskqueue.add(queue_name='push-msg-queue',
url=url_for("push_important_news"),
method='POST',
params={"key": key})
news.put()
return "Done", 200
示例7: delete_old_news
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def delete_old_news():
q = NewsEntry.query(NewsEntry.important == True).order(-NewsEntry.published)
ndb.delete_multi(q.fetch(offset=app.config["PER_PAGE"], keys_only=True))
q = NewsEntry.query(NewsEntry.important == False).order(-NewsEntry.published)
ndb.delete_multi(q.fetch(offset=app.config["PER_PAGE"], keys_only=True))
return "Done", 200
示例8: get_important_news
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def get_important_news():
data = memcache.get(key="important_news")
if data is None:
q = NewsEntry.query(NewsEntry.important==True).order(-NewsEntry.published)
data = ndb.get_multi(q.fetch(limit=app.config["PER_PAGE"],keys_only=True))
memcache.add(key="important_news", value=data, time=app.config["INDEX_CACHE_TIME"])
return data
示例9: create_oauth_app
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def create_oauth_app(service_config, name):
"""Creates oauth app for particaular web service
Args:
service_config (dict): config required for creating oauth app
name (string): name of the service, e.g github
"""
upper_name = name.upper()
app.config[upper_name] = service_config
service_oauth = oauth.OAuth()
service_app = service_oauth.remote_app(name, app_key=upper_name)
service_oauth.init_app(app)
return service_app
示例10: client
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def client():
""" Instantiate Flask's modified Werkzeug client to use in tests """
app.config["TESTING"] = True
app.config["DEBUG"] = True
return app.test_client()
# Routes that don't return 200 OK without certain query/post parameters or external services
示例11: client
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def client():
""" Instantiate Flask's modified Werkzeug client to use in tests """
app.config["TESTING"] = True
app.config["DEBUG"] = True
return app.test_client()
示例12: library_check_auth
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def library_check_auth(content, renew=False):
"""检查有无授权,进行查询或续借"""
user_library_info = get_user_library_info(openid)
if user_library_info:
# 解密密码
cipher = AESCipher(app.config['PASSWORD_SECRET_KEY'])
librarypwd = cipher.decrypt(user_library_info['librarypwd'])
library.borrowing_record.delay(
openid, user_library_info['libraryid'], librarypwd, renew=renew)
return wechat.response_text(content)
else:
url = app.config['HOST_URL'] + '/auth-library/' + openid
content = app.config['AUTH_LIBRARY_TEXT'] % url
return wechat.response_text(content)
示例13: exam_grade
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def exam_grade():
"""查询期末成绩"""
user_student_info = get_user_student_info(openid)
if user_student_info:
# 解密密码
cipher = AESCipher(app.config['PASSWORD_SECRET_KEY'])
studentpwd = cipher.decrypt(user_student_info['studentpwd'])
score.get_info.delay(openid, user_student_info['studentid'], studentpwd)
return wechat.response_text('查询中……')
else:
url = app.config['HOST_URL'] + '/auth-score/' + openid
content = app.config['AUTH_JW_TEXT'] % url
return wechat.response_text(content)
示例14: search_books
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def search_books():
"""图书馆找书"""
content = app.config['LIBRARY_TEXT'] + app.config['HELP_TEXT']
return wechat.response_text(content)
示例15: chat_robot
# 需要导入模块: from main import app [as 别名]
# 或者: from main.app import config [as 别名]
def chat_robot():
"""聊天机器人"""
timeout = int(message.time) - int(get_user_last_interact_time(openid))
# 超过一段时间,退出模式
if timeout > 20 * 60:
set_user_state(openid, 'default')
content = app.config['CHAT_TIMEOUT_TEXT'] + app.config['HELP_TEXT']
return wechat.response_text(content)
else:
simsimi.chat.delay(openid, message.content)
return 'success'