打印带有参数

时间:2018-05-04 18:26:56

标签: python django flask

如何打印出带参数的函数? 这是我的功能,但需要args,我试过   用市场和物品作为我的参数调用函数,但它说市场没有定义

更新:我已经添加了额外的代码,其他args继承自list market_catalogue和parse_event

@shared_task(bind=True)
def list_market_catalogue(self):
    logger.warning('+' * 80)
    trading = get_betfair_client()
    time_ago = timezone.now() + datetime.timedelta(minutes=1000)
    time_fwd = timezone.now() + datetime.timedelta(minutes=6000)
    mfilter = market_filter(
        event_type_ids=[ET_TENNIS] ,
        market_start_time=time_range(
        from_=time_ago.strftime('%Y-%m-%dT%H:%I:%S.000Z') ,
        to=time_fwd.strftime('%Y-%m-%dT%H:%I:%S.000Z')
        )
     )
     res = trading.betting.list_market_catalogue(
         mfilter ,
         market_projection=[
        'EVENT' ,
        'MARKET_START_TIME' ,
        # 'MARKET_DESCRIPTION',
        # 'RUNNER_METADATA',
        ] ,
        sort='FIRST_TO_START' ,
        max_results=1000 ,
        lightweight=True)
     if not len(res):
         logger.error('Market catalogue listing is empty')
         trading.session_token = None
        # raise self.retry(countdown=5 , max_retries=12)

    for cat in res:
        if 'venue' not in cat['event']:
            logger.error(f'No event venue in {cat}')
            continue
        try:
            event = parse_event(cat['event'])
            market = parse_market(event , cat)
            runners = parse_runners(market , cat['runners'])
         except:
            logger.warning(cat)
            raise
            logger.warning(f'BETFAIR: Scraped {len(res)} from market 
            catalogue')





@shared_task
def parse_event(event):
    """Parses event from Event object"""
    event , created = Event.objects.update_or_create(
        event_id=event['id'] ,
        defaults={
            'open_date': parse_datetime(event['openDate']) ,
            'venue': event['venue'].upper() ,
            'name': event['name'] ,
            'country_code': event['countryCode'] ,
            'timezone': event['timezone'] ,
        }
    )
    if created:
        logger.warning(f'Created {event}')
    else:
        logger.info(f'Updated {event}')

    return event


@shared_task
def parse_market(event , cat):
    """Parses market from MarketCatalogue object
    :rtype: object
    """
    market , created = Market.objects.update_or_create(
        market_id=cat['marketId'] ,
        defaults={
        'event': event ,
        # catalogue
        'name': cat['marketName'] ,
        'total_matched': cat['totalMatched'] ,
        'start_time': parse_datetime(cat['marketStartTime']) ,
        # description
        'betting_type': cat['description']['bettingType'] ,
        'market_time': parse_datetime(cat['description'] 
         ['marketTime']) ,
        'market_type': cat['description']['marketType'] ,
        'suspend_time': parse_datetime(cat['description'] 
        ['suspendTime']) ,
        'turn_in_play_enabled': cat['description'] 
        ['turnInPlayEnabled'] ,
        'race_type': cat['description'].get('raceType') ,
        }
    )
    if created:
        logger.warning(f'Created {market}')
    else:
        logger.info(f'Updated {market}')
    return market


def parse_runners(market , items):
    """Parses runners from MarketCatalogue object"""
    runners = []
    for runner_item in items:
        num = runner_item['metadata'].get('CLOTH_NUMBER')
        if not num:
            matches = re.match(r'^(\d+)' , runner_item['runnerName'])
            if matches:
                num = matches.groups(0)[0]
            else:
                logger.error(f'Could not match number for 
                {runner_item}')
        runner , created = Runner.objects.update_or_create(
            selection_id=runner_item['selectionId'] ,
            defaults={
            'market': market ,
            # default
            'name': runner_item['runnerName'].upper() ,
            'sort_priority': runner_item['sortPriority'] ,
            'handicap': runner_item['handicap'] ,
            # metadata
            'cloth_number': num ,
            'stall_draw': runner_item['metadata'].get('STALL_DRAW') ,
            'runner_id': runner_item['metadata']['runnerId'] ,
            }
        )
        if created:
            logger.info(f'Created {runner}')
       else:
            logger.debug(f'Updated {runner}')
        runners.append(runner)

    return runners
parse_runners(market, items)   

1 个答案:

答案 0 :(得分:1)

在调用mounted () { // first mount your 3rd party plugin on it's element $('#mountelement').plugin() this.$nextTick(()=>{ document.querySelectorAll('.holder button').forEach(button => { button.addEventListener('click', () => { console.log('a'); }, false); }); }) }

之前,如果没有任何其他信息,您似乎还没有定义if (strpos($res, "VERIFIED") !== 0)(可能也没有market

例如:

items