def fixture_data(): peerplays.clear() BettingMarkets.clear_cache() Rules.clear_cache() BettingMarketGroups.clear_cache() Proposals.clear_cache() Witnesses.clear_cache() Events.clear_cache() EventGroups.clear_cache() Sports.clear_cache() with open(os.path.join(os.path.dirname(__file__), "fixtures.yaml")) as fid: data = yaml.safe_load(fid) [Account(x) for x in data.get("accounts", [])] [Account(x).store(x, "name") for x in data.get("accounts", [])] Witnesses.cache_objects([Witness(x) for x in data.get("witnesses", [])]) Sports.cache_objects([Sport(x) for x in data.get("sports", [])]) EventGroups.cache_objects( [EventGroup(x) for x in data.get("eventgroups", [])]) Events.cache_objects([Event(x) for x in data.get("events", [])]) BettingMarketGroups.cache_objects( [BettingMarketGroup(x) for x in data.get("bettingmarketgroups", [])]) BettingMarkets.cache_objects( [BettingMarket(x) for x in data.get("bettingmarkets", [])]) Rules.cache_objects([Rule(x) for x in data.get("rules", [])]) [Bet(x) for x in data.get("bets", [])] proposals = [] for proposal in data.get("proposals", []): ops = list() for _op in proposal["operations"]: for opName, op in _op.items(): ops.append([operations[opName], op]) # Proposal! proposal_id = proposal["proposal_id"] proposal_data = { "available_active_approvals": [], "available_key_approvals": [], "available_owner_approvals": [], "expiration_time": "2018-05-29T10:23:13", "id": proposal_id, "proposed_transaction": { "expiration": "2018-05-29T10:23:13", "extensions": [], "operations": ops, "ref_block_num": 0, "ref_block_prefix": 0, }, "proposer": "1.2.7", "required_active_approvals": ["1.2.1"], "required_owner_approvals": [], } proposals.append(Proposal(proposal_data)) Proposals.cache_objects(proposals, "1.2.1") Proposals.cache_objects(proposals, "witness-account")
def test_evg(self): EventGroups("1.20.0") EventGroups("1.20.0") Sports() Sports() Events("1.21.12") Events("1.21.12") BettingMarketGroups("1.22.12") BettingMarketGroups("1.22.12") BettingMarkets("1.24.241") BettingMarkets("1.24.241")
def test_lists(self): self.assertIsInstance(Sports(), list) self.assertIsInstance(EventGroups("1.20.2"), list) self.assertIsInstance(Events("1.21.2"), list) self.assertIsInstance(BettingMarketGroups("1.22.2"), list) self.assertIsInstance(Rules(), list) self.assertIsInstance(BettingMarkets("1.24.2"), list)
def getSportsAsList(self): try: sports = Sports(peerplays_instance=self.get_node()).sports return [(x["id"], x["name"][0][1]) for x in sports] except Exception as ex: raise NodeException("Sports could not be loaded: {}".format( self._get_exception_message(ex)))
def list(ctx, sport): """ [bookie] list the entire thing """ from .ui import maplist2dict from tqdm import tqdm from treelib import Node, Tree tree = Tree() tree.create_node("sports", "root") def formatname(o): if "name" in o: name = o.get("name") elif "description" in o: name = o.get("description") else: name = [] return "{} ({})".format( maplist2dict(name).get("en"), o["id"] ) if sport: sports = [Sport(sport, peerplays_instance=ctx.peerplays)] else: sports = Sports() for sport in tqdm(sports): tree.create_node( formatname(sport), sport["id"], parent="root") for eg in tqdm(sport.eventgroups): tree.create_node( formatname(eg), eg["id"], parent=sport["id"]) for e in tqdm(eg.events): tree.create_node( formatname(e), e["id"], parent=eg["id"]) for bmg in tqdm(e.bettingmarketgroups): tree.create_node( formatname(bmg), bmg["id"], parent=e["id"]) for bm in tqdm(bmg.bettingmarkets): tree.create_node( formatname(bm), bm["id"], parent=bmg["id"]) tree.show()
def find_id(self, **kwargs): """ Try to find an id for the object of the lookup on the blockchain .. note:: This only checks if a sport exists with the same name in **ENGLISH**! """ sports = Sports(peerplays_instance=self.peerplays) find_id_search = kwargs.get("find_id_search", [comparators.cmp_name("identifier")]) for sport in sports: if all([ # compare by using 'all' the funcs in find_id_search func(self, sport) for func in find_id_search ]): return sport["id"]
def retrieve_data(self): """Depending on your config file returns all the events of the blockchain as a list of dicts""" self._set_data() data = [] if self.sport_id is None and self.eventgroup_id is None: # no sport id is given, therefore we want to check all events for sport in Sports(): for eventgroup in EventGroups(sport["id"]): for event in Events(eventgroup["id"]): self._append_event(data, event) # sport id is given: only check its' events elif self.eventgroup_id is None: # no eventgroup id is given, therefore we check all of the sports events try: eventgroups = EventGroups(self.sport_id) except UnhandledRPCError: logging.warning( "Unhandled RPC Error in {0} for sport id. Sport ids have to start with 1.20.<>" .format(self.get_source_name())) return for eventgroup in eventgroups: for event in Events(eventgroup["id"]): self._append_event(data, event) # Eventgroup id is given: only check its' events else: try: events = Events(self.eventgroup_id) except UnhandledRPCError: logging.warning( "Unhandled RPC Error in {0} for event id. Eventgroup ids have start with 1.21.<>" .format(self.get_source_name())) for event in events: self._append_event(data, event) self._set_data(data)
def sports(ctx): """ [bookie] List sports """ sports = Sports(peerplays_instance=ctx.peerplays) click.echo(pretty_print(sports, ctx=ctx))
def getSports(): sports = Sports(peerplays_instance=ppy) # TODO Add pagination return sports.sports
def getSports(self): try: return Sports(peerplays_instance=self.get_node()).sports except Exception as ex: raise NodeException("Sports could not be loaded: {}".format( self._get_exception_message(ex)))