コード例 #1
0
def config(args, db):
    conf = get_from_db(db, 'config', args.username)

    if args.password:
        password = getpass.getpass()
        hashp256 = hashlib.sha256(password)
        base_pass = base64.encodestring(hashp256.digest())
        conf['userHashPassword'] = base_pass

    update_dict(conf, args, 'username')
    update_dict(conf, args, 'countryCode')
    update_dict(conf, args, 'webapiKey')
    update_dict(conf, args, 'webapiUrl')

    if 'sessionHandlePart' not in conf:
        conf['sessionHandlePart'] = 'uu'

    if 'countryCode' not in conf:
        conf['countryCode'] = 1

    if 'localVersion' not in conf:
        conf['localVersion'] = 1

    if 'userHashPassword' not in conf:
        conf['userHashPassword'] = '******'

    if 'webapiKey' not in conf:
        conf['webapiKey'] = 'default'

    if 'webapiUrl' not in conf:
        conf['webapiUrl'] = 'https://webapi.allegro.pl/service.php?wsdl'

    update_in_db(db, 'config', conf, args.username)
コード例 #2
0
def add_buy(args, db):
    buy = get_from_db(db, 'buy', args.id)

    update_dict(buy, args, 'id')
    update_dict(buy, args, 'desc')
    update_dict(buy, args, 'status')

    if 'status' not in buy:
        buy['status'] = buy_stats['NOTDONE']

    if 'desc' not in buy:
        buy['desc'] = 'empty desc'

    update_in_db(db, 'buy', buy, args.id)
コード例 #3
0
def getShiftTime(data):
    with log_and_ignored(Exception):
        db = data['db']
        username = data['username']
        config = get_from_db(db, 'config', username)
        client = data['client']
        config_locker = data['config_locker']
        timeRes = client.service.doGetSystemTime(countryId=config['countryCode'], webapiKey=config['webapiKey'])
        with config_locker:
            config_u = {}
            config_u['shiftTime'] = timeRes - nowToEpoch()
            config_u['status'] = config_stats['INITIALIZED']
            update_in_db(db, 'config', config_u, username)
        logging.debug("serwer time: %s" % (datetime.fromtimestamp(timeRes)))
コード例 #4
0
def doBids(data, buy, waiter):
    with log_and_ignored(Exception):
        buy_u = {} 
        db = data['db']
        username = data['username']
        config = get_from_db(db, 'config', username)
        client = data['client']
        for bid in get_all_from_db(db, 'bid'):
            if bid['status'] == bid_stats['NOTBIDDED'] and bid['buy_id'] == buy['id']:
                bid_u = {}
                serverNow = nowToEpoch() + float(config['shiftTime'])
                session = config['sessionHandlePart']
                logging.debug(bid)
                logging.debug("calculated time: %s" % (datetime.fromtimestamp(serverNow)))

                whenShot = bid['whenShot']
                whenShot = float(whenShot)
                whenShot = round(whenShot)
                
                price = bid['price']
                price = float(price)
                quantity = bid['quantity']
                quantity = int(quantity)
                bid_id = bid['id']

                finishTime = bid.get('finishTime', None)
                if finishTime is None:
                    continue

                finishTime = int(finishTime)
                if serverNow > finishTime + whenShot and serverNow < finishTime + 5:
                    buy_u['status'] = buy_stats['BIDDED']
                    bid_u['status'] = bid_stats['BIDDED']
                    try:
                        logging.info("bidding %s" % (bid_id,))
                        client.service.doBidItem(sessionHandle=session,
                                                 bidItId=bid_id,
                                                 bidUserPrice=price,
                                                 bidQuantity=quantity)
                        ret = checkWinning(data, bid)
                        logging.info('doBids ret(%s) %s' % (ret, bid))
                        if ret == bid_stats['NOTWON']:
                            buy_u['status'] = buy_stats['NOTDONE']
                            bid_u['status'] = bid_stats['FINISHED']
                        if ret == bid_stats['WON']:
                            buy_u['status'] = buy_stats['DONE']
                            bid_u['status'] = bid_stats['FINISHED']
                            update_in_db(db, 'bid', bid_u, bid_id)
                            break
                        if ret == bid_stats['WINNING']:
                            bid_u['status'] = bid_stats['BIDDED']
                            update_in_db(db, 'bid', bid_u, bid_id)
                            break
                    except Exception, e:
                        logging.error("error %s" % (e.message.encode('utf-8')))
                update_in_db(db, 'bid', bid_u, bid_id)
        update_in_db(db, 'buy', buy_u, buy['id'])
        waiter.set()
コード例 #5
0
def getConfig(data):
    with log_and_ignored(Exception):
        db = data['db']
        username = data['username']
        config = get_from_db(db, 'config', username)
        config_locker = data['config_locker']
        client = data['client']
        g = client.service.doQueryAllSysStatus(config['countryCode'], config['webapiKey'])
        ver = [x['verKey'] for x in g[0] if x['countryId'] == 1][0]
        with config_locker:
            update_in_db(db, 'config', dict(localVersion=str(ver)), username)
        logRes = client.service.doLoginEnc(userLogin=config['username'],
                                           userHashPassword=config['userHashPassword'],
                                           countryCode=config['countryCode'],
                                           localVersion=config['localVersion'],
                                           webapiKey=config['webapiKey'])
        logRes_u = {}
        logRes_u['sessionHandlePart'] = str(logRes['sessionHandlePart'])
        logRes_u['userId'] = str(logRes['userId'])
        with config_locker:
            update_in_db(db, 'config', logRes_u, username)
コード例 #6
0
def checkBids(data, buy, waiter):
    db = data['db']
    buy_u = {}
    for bid in get_all_from_db(db, 'bid'):
        if bid['status'] == bid_stats['BIDDED'] and bid['buy_id'] == buy['id']:
            bid_u = {}
            bid_id = bid['id']
            try:
                ret = checkWinning(data, bid)
                logging.debug('checkBids ret(%s) %s' % (ret, bid))
                if ret == bid_stats['NOTWON']:
                    buy_u['status'] = buy_stats['NOTDONE']
                    bid_u['status'] = bid_stats['FINISHED']
                if ret == bid_stats['WON']:
                    buy_u['status'] = buy_stats['DONE']
                    bid_u['status'] = bid_stats['FINISHED']
                    update_in_db(db, 'bid', bid_u, bid_id)
                    break
            except Exception, e:
                logging.error("error %s" % (e.message.encode('utf-8')))
            update_in_db(db, 'bid', bid_u, bid_id)
コード例 #7
0
def add_bid(args, db):
    bidbuy = get_from_db(db, 'bid', args.id)

    update_dict(bidbuy, args, 'whenShot')
    update_dict(bidbuy, args, 'price')
    update_dict(bidbuy, args, 'status')
    update_dict(bidbuy, args, 'quantity')
    update_dict(bidbuy, args, 'buy_id')
    update_dict(bidbuy, args, 'id')

    if 'whenShot' not in bidbuy:
        bidbuy['whenShot'] = -3

    if 'price' not in bidbuy:
        bidbuy['price'] = 0

    if 'status' not in bidbuy:
        bidbuy['status'] = bid_stats['NOTBIDDED']

    if 'quantity' not in bidbuy:
        bidbuy['quantity'] = 1

    update_in_db(db, 'bid', bidbuy, args.id)
コード例 #8
0
def checkInfo(data, buy):
    with log_and_ignored(Exception):
        db = data['db']
        username = data['username']
        config = get_from_db(db, 'config', username)
        client = data['client']
        for bid in get_all_from_db(db, 'bid'):
            if bid['buy_id'] == buy['id']:
                session = config['sessionHandlePart']
                whenShot = round(float(bid['whenShot']))
                if bid.get('buy_now', None) is None or bid.get('finishTime', None) is None or bid.get('name', None) is None or whenShot >= 0:
                    (finishTime, name, buy_now) = getInfos(bid['id'], config, client)
                    bid_u = {}
                    if finishTime is not None:
                        if whenShot >= 0:
                            serverNow = nowToEpoch() + float(config['shiftTime'])
                            bid_u['whenShot'] = round(serverNow - int(finishTime) + whenShot)
                        bid_u['finishTime'] = str(finishTime)
                    if name is not None:
                        bid_u['name'] = name
                    if buy_now is not None:
                        bid_u['buy_now'] = buy_now
                    update_in_db(db, 'bid', bid_u, bid['id'])
コード例 #9
0
            bid_id = bid['id']
            try:
                ret = checkWinning(data, bid)
                logging.debug('checkBids ret(%s) %s' % (ret, bid))
                if ret == bid_stats['NOTWON']:
                    buy_u['status'] = buy_stats['NOTDONE']
                    bid_u['status'] = bid_stats['FINISHED']
                if ret == bid_stats['WON']:
                    buy_u['status'] = buy_stats['DONE']
                    bid_u['status'] = bid_stats['FINISHED']
                    update_in_db(db, 'bid', bid_u, bid_id)
                    break
            except Exception, e:
                logging.error("error %s" % (e.message.encode('utf-8')))
            update_in_db(db, 'bid', bid_u, bid_id)
    update_in_db(db, 'buy', buy_u, buy['id'])
    waiter.set()

def getInfos(bid_id, config, client):
    with log_and_ignored(Exception):
        session = config['sessionHandlePart']
        items = client.factory.create("ArrayOfLong")
        items.item = [bid_id]
        try:
            res = client.service.doGetItemsInfo(sessionHandle=session, itemsIdArray=items)
            itemInfo = res['arrayItemListInfo']['item'][0]['itemInfo']
            finishTime = itemInfo['itEndingTime']
            name = itemInfo['itName']
            buy_now = itemInfo['itBuyNowActive']
            return (finishTime, name, buy_now)
        except Exception, e: