Ejemplo n.º 1
0
    def get_market_prices(self, market_id):
        if market_id not in self._static:
            static = self.client.get_market(market_id)
            self._static[market_id] = static
        else:
            static = self._static[market_id]
        id_to_name = dict(map(lambda x: (x['selection_id'], extract_horse_name(x['name'])), static['runners']))

        raw = self.client.get_market_prices(market_id)
        prices = raw['runners']
        scheduled_off = dateutil.parser.parse(static['marketTime']).replace(tzinfo=None)
        for px in prices:
            px['market_id'] = market_id
            px['country'] = static['countryISO3']
            px['event'] = static['name']
            px['course'] = ''
            px['scheduled_off'] = scheduled_off
            px['selection'] = id_to_name[px['selection_id']]
        return prices
Ejemplo n.º 2
0
    def get_market_prices(self, market_id):
        if market_id not in self._static:
            static = self.client.get_market(market_id)
            self._static[market_id] = static
        else:
            static = self._static[market_id]
        id_to_name = dict(map(lambda x: (x["selection_id"], extract_horse_name(x["name"])), static["runners"]))

        raw = self.client.get_market_prices(market_id)
        prices = raw["runners"]
        scheduled_off = dateutil.parser.parse(static["marketTime"]).replace(tzinfo=None)
        for px in prices:
            px["market_id"] = market_id
            px["country"] = static["countryISO3"]
            px["event"] = static["name"]
            px["course"] = ""
            px["scheduled_off"] = scheduled_off
            px["selection"] = id_to_name[px["selection_id"]]
        return prices
Ejemplo n.º 3
0
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
            }
Ejemplo n.º 4
0
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,
            }