def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.config = Config("config.yaml").config StreamHandler(sys.stdout).push_application() self.log = Logger("Aiko") self.osuapi = OsuApi(self.config["osuapi"], connector=AHConnector()) self.kv = self.loop.run_until_complete(_connect_redis(self))
def __init__(self, bot): self.bot = bot self.omdb = bot._config.get('OMDB', '_token') self.osu = OsuApi(bot._config.get('OSU', '_token'), connector=AHConnector()) bot.loop.create_task(self.temp_checker())
async def getStats(key, userid): class Stats: username = "" rank = 0 api = OsuApi(key, connector=AHConnector()) Data = await api.get_user(userid) Stats.username = Data[0].username Stats.rank = Data[0].pp_rank api.close() return (Stats)
def __init__(self, bot): self.bot = bot self.omdb = bot._config.get('OMDB', '_token') self.osu = OsuApi(bot._config.get('OSU', '_token'), connector=AHConnector()) with open('./resources/MBTIS.json') as f: self.scores = json.load(f) with open('./resources/MBTI.json') as f: self.questions = json.load(f) bot.loop.create_task(self.temp_checker())
def __init__(self, bot): self.bot = bot self.bancho_queue = self.bot.config.get('bancho_queue') self.bancho_nick = self.bot.config.get('bancho_nick') self.osu = OsuApi(self.bot.config.get('osu_api_key'), connector=AHConnector()) tillerino_key = self.bot.config.get('tillerino_api_key') if tillerino_key: self.tillerino = TillerinoApi(tillerino_key) else: self.tillerino = None self.twitch_channel = self.bot.config.get('twitch_channel') if not self.twitch_channel.startswith('#'): self.twitch_channel = '#{}'.format(self.twitch_channel)
async def getResult(key, id, maps): class Result: datetime = "" users = [] wins = [] score = {} totalScore = {} scoreDiff = {} api = OsuApi(key, connector=AHConnector()) Data = await api.get_match(id) Result.datetime = Data.match.end_time Games = Data.games Result.users = [(Games[0].scores[0].user_id), (Games[0].scores[1].user_id)] for game in Games: if str(game.beatmap_id) in maps: stats = game.scores Result.score[stats[0].user_id] = Result.score.get( stats[0].user_id, 0) Result.score[stats[1].user_id] = Result.score.get( stats[1].user_id, 0) Result.totalScore[stats[0].user_id] = Result.totalScore.get( stats[0].user_id, 0) + stats[0].score Result.totalScore[stats[1].user_id] = Result.totalScore.get( stats[1].user_id, 0) + stats[1].score if (stats[0].score > stats[1].score): Result.wins.append(stats[0].user_id) Result.score[stats[0].user_id] = Result.score.get( stats[0].user_id, 0) + 1 Result.scoreDiff[stats[0].user_id] = Result.scoreDiff.get( stats[0].user_id, 0) + (stats[0].score - stats[1].score) elif (stats[0].score < stats[1].score): Result.wins.append(stats[1].user_id) Result.score[stats[1].user_id] = Result.score.get( stats[1].user_id, 0) + 1 Result.scoreDiff[stats[1].user_id] = Result.scoreDiff.get( stats[1].user_id, 0) + (stats[1].score - stats[0].score) else: pass else: pass api.close() return (Result)
async def get_user(user, mode): from osuapi import OsuApi, AHConnector, enums osu_collection = database['osu_profiles'] if isinstance(user, int): cursor = osu_collection.find({'user_id': str(user)}) document = await cursor.to_list(length=1) try: document = document[0] user = document['osu_user'] except IndexError: return None regex = re.compile(r'^(?:http)s?://osu\.ppy\.sh/users/' ) # Regex to check if a link is provided if user.isdigit(): # If user provided an ID user = int(user) elif re.match(regex, user) is not None: # If user provided an link link_split = user.split('/') user_id = [i for i in link_split if i.isdigit()] # Get the user ID user = int(user_id[0]) # Convert ID into integer elif user.isalpha(): # If user provided a username pass if mode == 'taiko': # If taiko mode selected gamemode = enums.OsuMode.taiko elif mode == 'ctb' or mode == 'catch' or mode == 'fruits': # If catch the beat mode selected gamemode = enums.OsuMode.ctb elif mode == 'mania': # If mania mode selected gamemode = enums.OsuMode.mania else: # Set default gamemode gamemode = enums.OsuMode.osu api = OsuApi(Constants.osu_api_key, connector=AHConnector()) # Connect to osu! API result = await api.get_user(user, mode=gamemode) try: user_data = result[0] except IndexError: user_data = None return user_data
def __init__(self, bot): self.api = OsuApi(config.osu, connector=AHConnector()) self.bot = bot
def __init__(self, bot): self.bot = bot self.redis = bot.db.redis self.bot.say_edit = bot.says_edit self.api = OsuApi(utils.OS_Get("osu"), connector=AHConnector())
def __init__(self, bot): self.bot = bot if bot.config['osu']: self.api = OsuApi(bot.config['osu'], connector=AHConnector()) else: self.api = None
# coll.find_one() # coll.find().count() # coll.save({'test': 1}) # coll.find_one() # coll.find().count() # coll.update({'test': 1}, {'test': 2}) # coll.find_one() # coll.find().count() if __name__ == '__main__': apikey = # your Osu! API key user_ids = random.sample(range(1, 5000000), 500000) api = OsuApi(apikey, connector=AHConnector()) collected = 0 i = 0 requests = 0 while requests < 550000: user_id = user_ids[i] try: results = asyncio.get_event_loop().run_until_complete(get_user_recent(api, user_id)) requests += 1 time.sleep(0.25) if results != []: for result in results: user_recent.save(parse_user_recent(result, user_id)) collected = collected + 1 ''' else:
import aiohttp import os from osuapi import OsuApi, AHConnector osu_api = OsuApi(os.getenv("osu_token"), connector=AHConnector()) class Api: requests = 0 @staticmethod async def get_user(username): try: get_user = await osu_api.get_user(username) Api.requests += 1 return get_user[0] except IndexError: return @staticmethod async def get_user_recent(user_id, limit=0, lslist=False): try: get_user_recent = await osu_api.get_user_recent(user_id, limit=limit + 1) Api.requests += 1 return get_user_recent[limit if lslist is False else None] except IndexError: return except TypeError:
embed.set_thumbnail(url=thumbnail) await channel.send(embed=embed) else: return await message.add_reaction('✅') logging.basicConfig(level=logging.INFO) with open('config.toml', 'r') as f: config = toml.load(f) session = aiohttp.ClientSession() osu_api = OsuApi(config['api_keys']['osu'], connector=AHConnector()) tracker = Tracker() async def main(): await add_users_to_tracker() client = MyClient() try: await client.start(config['api_keys']['discord']) except KeyboardInterrupt: pass finally: await client.close() await session.close()
def __init__(self, bot): self.bot = bot self.redis = bot.db.redis self.api = OsuApi(utils.secret["osu"], connector=AHConnector())