def get_future_markets(menu_prefix='\\Horse Racing\\GB', hours=24): client = API_T() client.login(USERNAME, PASSWORD) now = datetime.datetime.utcnow() before_date = now + datetime.timedelta(hours=hours) markets = client.get_all_markets(hours=24) logging.info('Getting all markets..') if isinstance(markets, str): raise RuntimeError(markets) markets = ifilter(lambda x: before_date > x['event_date'] > now and x['menu_path'].startswith(menu_prefix), markets) for m in markets: detailed = client.get_market(m['market_id']) if isinstance(detailed, str): raise RuntimeError(detailed) runners, selection_ids = [], [] invalid_selection = False for r in detailed['runners']: horse_name = extract_horse_name(r['name']) if horse_name is None: logging.warning('Skipping market with id=%s as selection="%s" is not a horse name.' % (m['market_id'], r['name'])) invalid_selection = True break runners.append(horse_name) selection_ids.append(r['selection_id']) if not invalid_selection: yield { 'country': detailed['countryISO3'], 'course': m['menu_path'].split('\\')[-1], 'event': m['market_name'], 'market_id': m['market_id'], 'scheduled_off': dateutil.parser.parse(detailed['marketTime']).replace(tzinfo=None), 'n_runners': len(runners), 'selection': runners }
def __init__(self, username=USERNAME, password=PASSWORD): super(PaperExecutionService, self).__init__() self.client = API_T() self.client.login(username, password) self._static = {}