def loop(self): app = create_app() with app.app_context(): bcolors.run('Worker start at mq tube [%s]...' % self.tube) try: while True: self.consume() except KeyboardInterrupt: bcolors.success('Worker at mq tube [%s] success stopped.' % self.tube)
def main(): bcolors.run('Add OAuth client.') client = OAuthClient.add(name=u'OAuthy', redirect_uri=get_redirect_uri(), allowed_grant_types=[ 'authorization_code', 'password', 'refresh_token' ], allowed_response_types=['token', 'code'], allowed_scopes=[ OAuthScope.user_info, OAuthScope.savings_r, OAuthScope.savings_w, OAuthScope.wallet_r, OAuthScope.wallet_w ]) client_args = (client.name, client.client_id, client.client_secret) bcolors.run('%s: %s %s ' % client_args, key='oauth') bcolors.run('Add OAuth authorization.') app = create_app() with app.app_context(), app.test_client() as http: r = http.post( url_for('api.oauth.access_token'), data={ 'grant_type': 'password', 'client_id': client.client_id, 'client_secret': client.client_secret, 'username': '******', 'password': '******', 'scope': 'basic user_info savings_r savings_w wallet_r wallet_w', }) if not bearychat.configured: return bearychat.say(TEMPLATE.format(client.client_id, client.client_secret)) data = json.loads(r.data) bcolors.run(' '.join('%s=%s' % pair for pair in data.items()), key='oauth')
#!/usr/bin/env python # -*- coding:utf-8 -*- """ 订单状态同步及资产补录 """ from collections import Counter from jupiter.app import create_app from jupiter.ext import sentry from jupiter.workers.hoarder import (hoarder_payment_tracking, hoarder_redeem_tracking, hoarder_asset_fetching) from libs.logger.rsyslog import rsyslog app = create_app() MAX_RETRY = 2 def main(): tasks = [ hoarder_payment_tracking, hoarder_redeem_tracking, hoarder_asset_fetching ] for task in tasks: mq = task.get_broker() counter = Counter() while True: job = mq.peek_buried() if not job:
def peep_session(self): app = create_app() with app.app_context(): cookies = self.browser.cookies.all() return app.open_session(storify({'cookies': cookies}))
def url_for(self, endpoint, **kwargs): app = create_app() with app.app_context(): return flask.url_for(endpoint, **kwargs)
def main(): app = create_app() with app.app_context(): mails = Mail.create(RECEIVERS, spring_interview_mail) Mail.send_multi(mails)
try: register_zhiwang_account(user.id_) zhiwang_account = ZhiwangAccount.get_by_local(user.id_) except (MismatchUserError, RepeatlyRegisterError) as e: bcolors.fail(e.args[0], key='zhiwang_code') return bcolors.run('The new zhiwang code is %s' % zhiwang_account.zhiwang_id, key='zhiwang_code') with open(ADD_ZHIWANG_FILE, 'r') as f: source = RE_ZHIWANG_CODE.sub( "ZHIWANG_TOKEN = u'%s'" % zhiwang_account.zhiwang_id.encode('ascii'), f.read()) with open(ADD_ZHIWANG_FILE, 'w') as f: f.write(source) bcolors.run('%s is changed. PLEASE COMMIT IT AND OPEN A MERGE REQUEST.' % ADD_ZHIWANG_FILE, key='zhiwang_code') if '--commit' in sys.argv: subprocess.check_call( ['git', 'commit', '-m', COMMIT_MSG, '--', ADD_ZHIWANG_FILE]) if __name__ == '__main__': with create_app().app_context(): main()
def app(sqlstore, redis): app = create_app(TestingConfig()) with app.app_context(): yield app