def __init__(self, bot): self.bot = bot self.conv = TagCheck() self.cache = TTLCache(500, 180) scopes = [ "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/firebase.database" ] self.firebase = ServiceAccountCredentials.from_json_keyfile_dict( json.loads(b64decode(os.getenv('firebase')).decode()), scopes=scopes) try: constants = json.loads( requests.get('https://fourjr.herokuapp.com/cr/constants').text) except json.JSONDecodeError: constants = None self.cr = clashroyale.OfficialAPI( os.getenv('clashroyale'), session=self.bot.session, is_async=True, timeout=20, constants=constants, url= f"http://{os.getenv('spike')}/redirect?url=https://api.clashroyale.com/v1" ) self.royaleapi = clashroyale.RoyaleAPI(os.getenv('royaleapi'), session=self.bot.session, is_async=True, timeout=20) if not self.bot.dev_mode: self.bot.clan_update = self.bot.loop.create_task( self.clan_update_loop())
def __init__(self, clan_tag: str, key: str, api: str, sleep_seconds: int) -> None: self.clan_tag: str = clan_tag self.key: str = key self.sleep_seconds = sleep_seconds self.api = api if api.lower() == ROYALE_API: self.client = clashroyale.RoyaleAPI(key, is_async=False) else: self.client = clashroyale.OfficialAPI(key, is_async=False)
def __init__(self, configfile_name, debug=False, disable_cache=False): if debug: logging.basicConfig( level=logging.DEBUG, format='%(levelname)s: %(asctime)s: %(message)s') else: logging.basicConfig( level=logging.INFO, format='%(levelname)s: %(asctime)s: %(message)s') logging.info('##### Started ClashRoyalOneKFinder #####') self._debug = debug self._disable_cache = disable_cache self._config = Config(configfile_name) self._clashroyale = clashroyale.RoyaleAPI( self._config.clashroyale_api_key()) self._device_list = self._config.device_list() self._notified_games = NotifiedGamesList('notified-games.pkl', disable_cache=disable_cache)
def __init__(self): super().__init__(command_prefix=None, case_insensitive=True) self.session = aiohttp.ClientSession(loop=self.loop) self.royaleapi = clashroyale.RoyaleAPI(os.environ.get('ROYALEAPI'), is_async=True, timeout=10, session=self.session) self.add_command(self.ping) for c in os.listdir('cogs'): if c.endswith('.py') and c not in (): try: self.load_extension('cogs.' + c.replace('.py', '')) except Exception as e: print(f'Failed {c}: {e}') else: print(f'Loaded {c}') self.run(os.environ.get('TOKEN'), activity=discord.Game('for Aurora eSports'))
async def main(): client = clashroyale.RoyaleAPI(token, is_async=True) # is_async=True argument # EVERYTHING IS THE SAME, BUT WITH await's profile = await client.get_player('CY8G8VVQ') print(repr(profile)) print(profile.name) print(profile.league_statistics) await profile.refresh() print(profile.stats.favorite_card.name) clan = await profile.get_clan() print(clan) print(clan.member_count) await clan.refresh() member = clan.members[0] assert member.clan is clan assert member.rank == 1 await member.get_player() # full player clans = await client.get_clans('2CCCP', '2U2GGQJ') # 7 max amount of arguments for clan in clans: print(clan.members[0]) client.close()
def setUp(self): self.cr = clashroyale.RoyaleAPI(TOKEN, url=URL, timeout=30)
def __init__(self): self.client = clashroyale.RoyaleAPI(CR_KEY)
def __init__(self, bot): self.bot = bot self.auth = self.bot.get_cog('crtools').auth self.clash = clashroyale.RoyaleAPI(self.auth.getToken(), is_async=True)
async def setUp(self): self.cr = clashroyale.RoyaleAPI(TOKEN, url=URL, is_async=True, loop=self.loop, timeout=30)
def __init__(self): self._key = os.getenv('MY_TOKEN_DISCORD', 'Token Not Found') self._client = clashroyale.RoyaleAPI(self._key)
import clashroyale import os c = clashroyale.RoyaleAPI( token=os.getenv('crtoken'), cache_fp='cache.db', cache_expires=10 # Seconds before client should request from api again. ) for _ in range(100): model = c.get_top_clans() print( model, model.cached, # Bool indicating whether or not the data is cached. model.last_updated ) # Datetime for the time the data was last updated from the API. # Finished very quickly due to caching!
def __init__(self, *args, **kwargs): self.clashroyale_client = clashroyale.RoyaleAPI(TOKEN, url=URL, timeout=30) super().__init__(*args, **kwargs)
def getJsonWithCache(): # initialise list of dico r_listeMembers = [] r_history = [] r_warlog = [] # get current date today = date.today() # create APIROYALE client client = clashroyale.RoyaleAPI(apiToken, cache_fp='cache.db', cache_expires=10) try: # get player data profile = client.get_player(playerId) except: print('error profile ID') try: # get clan data from player ID clan = profile.get_clan() # get all clan members for member in clan.members: # create the member list lineMember = { F_TAG: member[F_TAG], F_NAME: removeSpecialChars(member[F_NAME]) } # create the history lineHistory = { F_TAG: member[F_TAG], F_DATE: str(today), F_ROLE: member[F_ROLE], F_EXPLEVEL: int(member[F_EXPLEVEL]), F_TROPHIES: int(member[F_TROPHIES]), F_CLANRANK: int(member['rank']), F_DONATIONS: int(member[F_DONATIONS]), F_DONATIONSRECEIVED: int(member[F_DONATIONSRECEIVED]) } r_listeMembers.append(lineMember) r_history.append(lineHistory) # get clan data r_clan = { F_CLANNAME: removeSpecialChars(clan[F_NAME]), F_CLANDESCRIPTION: removeSpecialChars(clan[F_CLANDESCRIPTION]), F_MEMBERCOUNT: int(clan[F_MEMBERCOUNT]), F_REQUIREDSCORE: int(clan[F_REQUIREDSCORE]) } except: print('error clan ID') try: # get war log for clan ID warList = client.get_clan_war_log(clanId) # for all past wars for war in warList: uncompleteWar = False # decode war date (unix timestamp) dateWar = datetime.utcfromtimestamp( war['createdDate']).strftime('%Y-%m-%d') # for all members of the war for member in war['participants']: # if war war uncompleted (prepataion < 3 or war < 1) if ((member[F_PREPAPLAYED] < 3) or (member[F_BATTLESPLAYED] == 0)): # create a war log entry lineWarLog = { F_TAG: member[F_TAG], F_DATEWAR: dateWar, F_PREPAPLAYED: int(member[F_PREPAPLAYED]), F_BATTLESPLAYED: int(member[F_BATTLESPLAYED]) } uncompleteWar = True r_warlog.append(lineWarLog) # if all battles were done by all members if uncompleteWar == False: # create a fake complete entry in order to log the clan participation to the war # this entry will have a tag set to 'none' et had to be filterd in sql requests lineWarLog = { F_TAG: 'none', F_DATEWAR: dateWar, F_PREPAPLAYED: 3, F_BATTLESPLAYED: 1 } r_warlog.append(lineWarLog) except: print('error clan war') client.close() return r_clan, r_listeMembers, r_history, r_warlog
def getJsonWithCache(i_apiToken, i_playerId, i_clanId): # initialise list of dico r_history = [] r_warlog = [] # create APIROYALE client client = clashroyale.RoyaleAPI(i_apiToken, cache_fp='cache.db', cache_expires=10) try: # get player data profile = client.get_player(i_playerId) except: print('error profile ID') try: # get clan data from player ID clan = profile.get_clan() # get all clan members for member in clan.members: #if (int(member[conf.F_DONATIONS]) < conf.K_CLANLIMITE): r_history.append([ utils.removeSpecialChars(member[conf.F_NAME]), int(member[conf.F_DONATIONSRECEIVED]), int(member[conf.F_DONATIONS]) ]) # get clan data r_clan = { conf.F_NAME: utils.removeSpecialChars(clan[conf.F_NAME]), conf.F_CLANDESCRIPTION: utils.removeSpecialChars(clan[conf.F_CLANDESCRIPTION]), conf.F_MEMBERCOUNT: int(clan[conf.F_MEMBERCOUNT]), conf.F_REQUIREDSCORE: int(clan[conf.F_REQUIREDSCORE]) } except: print('error clan ID') try: # get war log for clan ID warList = client.get_clan_war_log(i_clanId) # for all past wars war = warList[0] # decode war date (unix timestamp) r_dateWar = datetime.utcfromtimestamp( war['createdDate']).strftime('%Y-%m-%d') participant = [] prepaWar = [] finalWar = [] # for all members of the war for member in war['participants']: # if war war uncompleted (prepataion < 3 or war < 1) if ((member[conf.F_PREPAPLAYED] < 3) or (member[conf.F_BATTLESPLAYED] == 0)): participant.append(member[conf.F_NAME]) prepaWar.append(int(member[conf.F_PREPAPLAYED])) finalWar.append(int(member[conf.F_BATTLESPLAYED])) r_warlog = [participant, prepaWar, finalWar] except: print('error clan war') client.close() return r_clan, r_history, r_warlog, r_dateWar
import clashroyale import os # Basic functionality token = os.getenv('crtoken') # get your developer key somehow. client = clashroyale.RoyaleAPI(token) profile = client.get_player('#8l9l9gl') # library cleans the tag (strips #) print(repr(profile)) print(profile.name) # Access data via dot notation. print(profile.stats.favorite_card.name) # Access API data via snake_case instead of camelCase # Everything is exactly the same as what is # presented in the official API documentation # # { # "stats": { # "favoriteCard": { # "name": "P.E.K.K.A" # }, # ... # }, # ... # profile.refresh()