本文整理匯總了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'