Exemple #1
0
def order_status(order_id, new_status):
    """Edits the status of specific order."""
    if new_status in remote_statuses():
        new_status = new_status.decode(sys.stdin.encoding)
    else:
        status_list = ', '.join(remote_statuses())
        bcolors.fail('status must be one of %s' % status_list)
        return

    order = HoardOrder.get(order_id)
    if not order:
        bcolors.fail('order not found')
        return

    profile = HoardProfile.get(order.user_id)
    matched_index = [
        index for index, order_info in enumerate(profile.person_account_info)
        if order_info['finOrderNo'] == order.fin_order_id
    ]

    if not matched_index:
        bcolors.fail('failed')
        return

    account_info = list(profile.person_account_info)
    account_info[matched_index[0]]['finOrderStatus'] = unicode(new_status)
    profile.person_account_info = account_info

    bcolors.success('done')
Exemple #2
0
def token_dump(user_alias, workdir=None):
    """Dumps API token from database."""
    account = Account.get_by_alias(user_alias)
    if not account:
        return bcolors.fail('user %r not found' % user_alias)

    workdir = os.path.expanduser(workdir or '~/.guihua')
    if not os.path.exists(workdir):
        os.makedirs(workdir)

    yixin_account = YixinAccount.get_by_local(account.id_)
    if not yixin_account:
        return bcolors.fail('%r need to bind yixin account' % user_alias)

    jsonfile_location = os.path.join(workdir, 'solar-yixin-token.json')

    if os.path.exists(jsonfile_location):
        with open(jsonfile_location) as jsonfile:
            data = json.load(jsonfile)
        if not isinstance(data, dict):
            return bcolors.fail('unexpected data')
    else:
        data = {}

    data[user_alias] = {
        'user_alias': user_alias,
        'yixin_account': yixin_account.p2p_account,
        'yixin_token': yixin_account.p2p_token,
    }

    with open(jsonfile_location, 'w') as jsonfile:
        json.dump(data, jsonfile, indent=4)

    bcolors.success('success: %s %s' % (user_alias, yixin_account.p2p_account))
Exemple #3
0
    def consume(self):
        broker = self.get_broker()
        job = broker.reserve()
        if job is None:
            return
        bcolors.success('Get job %s' % job.jid)
        self._send_log('get job %s' % job.jid)

        try:
            self.target(job.body)
        except KeyboardInterrupt:
            job.bury()
            raise
        except WorkerTaskError:
            sentry.captureException(level=logging.WARNING)
            job.bury()
        except Exception as e:
            sentry.captureException()
            bcolors.fail('job %s failed and bury. %s' %
                         (job.jid, unicode(e).encode('utf-8')))
            self._send_log('job %s failed and buried because %s' %
                           (job.jid, unicode(e).encode('utf-8')))
            job.bury()
        else:
            bcolors.success('Job process success.')
            job.delete()
            self._send_log('job %s deleted' % job.jid)
Exemple #4
0
def init():
    """Downloads the product data of Yixin."""
    try:
        response = yixin.query.p2p_service_list()
    except RemoteError as e:
        bcolors.fail('%s : %s : %s' % e.args)
    else:
        for service_info in response.data:
            service = YixinService.add(service_info)
            bcolors.success('YixinService: %s' % service.p2pservice_name)
Exemple #5
0
 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)
Exemple #6
0
def init():
    """Downloads the product data of sxb."""
    try:
        rs = sxb.query_products(ProductType.ririying)
    except ClientError as e:
        bcolors.fail('Fetching Sxb Product Failed:%s' % e)
    else:
        for product_info in rs:
            product = fillup_local(product_info)
            product = fillup_local(product_info, is_child_product=True)
            bcolors.success('SxbProduct: %s' % product.name)
Exemple #7
0
def init():
    """Synchronize the annual rates."""
    try:
        rates = WalletAnnualRate.synchronize(zslib.client, provider.fund_code)
    except BusinessError as e:
        bcolors.fail('%s : %s : %s' % e.args)
        return

    for rate in rates:
        bcolors.success('{0}\t{1}\t{2}\t¥{3}'.format(
            rate.date,
            rate.fund_code,
            round_half_up(rate.annual_rate, 2),
            round_half_up(rate.ten_thousand_pieces_income, 2),
        ))
Exemple #8
0
def main():
    bcolors.run('Add redeem code.')
    effective_time = datetime.now() - timedelta(days=1)
    expire_time = datetime.now() + timedelta(days=30)
    try:
        # 创建100个可被使用一次的兑换码
        RedeemCode.create_multi_codes(fanmeeting_gold.id_,
                                      RedeemCode.Kind.normal_package.value,
                                      u'测试用兑换码', 1, 100, effective_time,
                                      expire_time)
        # 创建一个可使用100次的兑换码
        RedeemCode.create(fanmeeting_silver.id_,
                          RedeemCode.Kind.normal_package.value, u'测试用兑换码', 100,
                          None, effective_time, expire_time)
        bcolors.success('Init redeemcode done.')
    except Exception as e:
        bcolors.fail('Init redeemcode fail: %s.' % e)
Exemple #9
0
def main():
    cities = [
        ('110000', '北京', 48531.85, 33717.45),
        ('310000', '上海', 48841.4, 35182.44),
        ('330000', '浙江', 40392.72, 27241.74),
        ('120000', '天津', 31506.03, 24289.64),
        ('130000', '河北', 24141.34, 16203.82),
        ('140000', '山西', 24069.43, 14636.88),
        ('150000', '内蒙古', 28349.64, 20885.23),
        ('210000', '辽宁', 29081.75, 20519.57),
        ('220000', '吉林', 23217.82, 17156.14),
        ('230000', '黑龙江', 22609.03, 16466.63),
        ('320000', '江苏', 34346.26, 23476.28),
        ('340000', '安徽', 24828.52, 16107.07),
        ('350000', '福建', 30722.39, 22204.06),
        ('360000', '江西', 24309.19, 15141.78),
        ('370000', '山东', 29221.94, 18322.60),
        ('410000', '河南', 23672.06, 16184.46),
        ('420000', '湖北', 24852.28, 16681.41),
        ('430000', '湖南', 26570.16, 18334.66),
        ('440000', '广东', 32148.11, 23611.74),
        ('450000', '广西', 24669, 15045.40),
        ('460000', '海南', 24486.53, 17513.78),
        ('500000', '重庆', 25147.23, 18279.49),
        ('510000', '四川', 22227.51, 17759.93),
        ('520000', '贵州', 22548.21, 15254.64),
        ('530000', '云南', 24299.01, 16268.33),
        ('540000', '西藏', 22015.81, 15669.36),
        ('610000', '陕西', 24365.76, 17545.96),
        ('620000', '甘肃', 21803.86, 15942.25),
        ('630000', '青海', 22306.57, 17492.89),
        ('640000', '宁夏', 23284.56, 17216.23),
        ('650000', '新疆', 23214.03, 17684.52),
        ('710000', '台湾', 24828.52, 16107.07),
    ]

    for city in cities:
        db.execute('insert INTO wxplan_salary(code,province,income,expenditure) '
                   'VALUES (%s, %s ,%s ,%s)', city)

    db.commit()

    bcolors.success('init province salary init done.')
Exemple #10
0
def init():
    """Downloads the product data of Zhiwang."""
    try:
        response = zhiwang.product_list()
    except RemoteError as e:
        bcolors.fail('Fetching Zhiwang Product Failed:%s' % e)
    else:
        all_products = []
        for product_info in response.products:
            base_product = ZhiwangProduct.add(product_info)
            bcolors.success('ZhiwangProduct: %s' % base_product.name)

            wrapped_products = ZhiwangWrappedProduct.get_multi_by_raw(base_product.product_id)
            for wp in wrapped_products:
                bcolors.success('ZhiwangWrappedProduct: %s' % wp.name)

            all_products.append(base_product)
            all_products.extend(wrapped_products)

        for p in all_products:
            # 测试环境默认上架
            p.is_taken_down = False
Exemple #11
0
def token_load(workdir=None):
    """Loads API token from local file."""
    workdir = os.path.expanduser(workdir or '~/.guihua')
    if not os.path.exists(workdir):
        return bcolors.fail('token not found')

    jsonfile_location = os.path.join(workdir, 'solar-yixin-token.json')
    if not os.path.exists(jsonfile_location):
        return bcolors.fail('token not found')

    with open(jsonfile_location) as jsonfile:
        data = json.load(jsonfile)

    for user_alias, item in data.iteritems():
        account = Account.get_by_alias(item['user_alias'])
        if not account:
            bcolors.fail('user %s not found' % user_alias)
            continue

        p2p_account = item['yixin_account']
        p2p_token = item['yixin_token']
        YixinAccount.bind(account.id_, p2p_account, p2p_token)

        bcolors.success('restored %s %s' % (account, p2p_account))
Exemple #12
0
# coding: utf-8

from libs.utils.log import bcolors
from core.models.hoarder.vendor import Vendor, Provider

if __name__ == '__main__':
    bcolors.run('Add product_vendor.')
    Vendor.add(Provider.sxb.value, 'sxb')
    Vendor.add(Provider.xm.value, 'xm')
    Vendor.add(Provider.zw.value, 'zw')
    Vendor.add(Provider.ms.value, 'ms')
    bcolors.success('Init product vendor done.')
Exemple #13
0
    # parser.add_option('-v', '--verbose', action='store_true')
    # parser.add_option('-q', '--quiet', action='store_true')
    # parser.add_option('-m', '--use-memory', action='store_true',
    #         help='use mysql memory engine for testing')
    parser.add_option(
        '-n',
        '--not-testing-database',
        action='store_true',
        help='use database in config. but the database name must starts '
        'with "test" or "sandbox")')
    parser.add_option('-d',
                      '--sql-schema-dir',
                      type='string',
                      help='load sql schema files from SQL_SCHEMA_DIR',
                      default='database')
    global options
    options, args = parser.parse_args()

    test_dir = os.path.dirname(os.path.realpath(__file__))
    shire_dir = os.path.dirname(test_dir)
    sys.path.append(shire_dir)

    store = None
    if options.not_testing_database:
        pass
    else:
        from tests.framework import init
        store = init()
    init_db_from_dir(store, options.sql_schema_dir)
    bcolors.success('Init db done.')
Exemple #14
0
# coding: utf-8

"""
创建测试用礼券
"""

from libs.utils.log import bcolors
from core.models.user.account import Account
from core.models.welfare.package.kind import test_newcomer_center


if __name__ == '__main__':
    bcolors.run('Add coupons.')

    # in init_user we create test%[email protected]
    try:
        emails = ['*****@*****.**' % r for r in range(9)]
        emails.append('*****@*****.**')
        for email in emails:
            user = Account.get_by_alias(email)
            package = test_newcomer_center.distributor.bestow(user)
            package.unpack(user)
        bcolors.success('Init coupon done.')
    except Exception as e:
        bcolors.fail('Init coupon fail: %s.' % e)
Exemple #15
0
            u = add_user(name, email, reg_type=ACCOUNT_REG_TYPE.EMAIL)
            if i < 5:
                p = Plan.add(u.id)
                p.data.secret_db.set(p.data.props_name, d)
                p.update_step(6)
                bcolors.run('email=%s, password=%s, plan=%s' %
                            (email, 'testtest', p.id),
                            key='user')
            else:
                bcolors.run('email=%s, password=%s' % (email, 'testtest'),
                            key='user')

        for i in range(10):
            name = 'mobiletest%s' % i
            mobile = '159%s' % (repr(i) * 8)
            u = add_user(name, mobile, reg_type=ACCOUNT_REG_TYPE.MOBILE)
            if i < 5:
                p = Plan.add(u.id)
                p.data.secret_db.set(p.data.props_name, d)
                p.update_step(6)
                bcolors.run('mobile=%s, password=%s, plan=%s' %
                            (mobile, 'testtest', p.id),
                            key='user')
            else:
                bcolors.run('mobile=%s, password=%s' % (mobile, 'testtest'),
                            key='user')

        bcolors.success('Init user done.')
    except Exception as e:
        bcolors.fail('Init user fail: %s.' % e)
Exemple #16
0
    (652200, '哈密地区', 650000),
    (652300, '昌吉回族自治州', 650000),
    (652700, '博尔塔拉蒙古自治州', 650000),
    (652800, '巴音郭楞蒙古自治州', 650000),
    (652900, '阿克苏地区', 650000),
    (653000, '克孜勒苏柯尔克孜自治州', 650000),
    (653100, '喀什地区', 650000),
    (653200, '和田地区', 650000),
    (654000, '伊犁哈萨克自治州', 650000),
    (654200, '塔城地区', 650000),
    (654300, '阿勒泰地区', 650000),
    (710000, '台湾省', 100000),
    (710100, '台湾地区', 710000),
    (810000, '香港特别行政区', 100000),
    (810100, '香港地区', 810000),
    (820000, '澳门特别行政区', 100000),
    (820100, '澳门地区', 820000),
]

bcolors.run('Add Location.')
try:
    for r in CITIES:
        db.execute(
            'insert into location '
            '(id, name_cn, parent_id) '
            'values (%s, %s, %s)', r)
    db.commit()
    bcolors.success('Add Location Done.')
except Exception as e:
    bcolors.fail('Init data fail: %r' % e)