示例#1
0
文件: mq.py 项目: c1xfr2e/soledad
 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)
示例#2
0
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')
示例#3
0
#!/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:
示例#4
0
 def peep_session(self):
     app = create_app()
     with app.app_context():
         cookies = self.browser.cookies.all()
         return app.open_session(storify({'cookies': cookies}))
示例#5
0
 def url_for(self, endpoint, **kwargs):
     app = create_app()
     with app.app_context():
         return flask.url_for(endpoint, **kwargs)
示例#6
0
def main():
    app = create_app()
    with app.app_context():
        mails = Mail.create(RECEIVERS, spring_interview_mail)
        Mail.send_multi(mails)
示例#7
0
    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()
示例#8
0
def app(sqlstore, redis):
    app = create_app(TestingConfig())
    with app.app_context():
        yield app