Example #1
0
    async def run(self, amount):
        # url = "http://localhost:8080/{}"
        tasks = []
        bttv_dict = FileHelper.JSONread(
            'C:\\Users\\BIGNIG\\Documents\\Python Scripts\\FrankerFaceZ\\emotedata_bttv.json'
        )
        # create instance of Semaphore
        sem = asyncio.Semaphore(100)

        # Create client session that will ensure we dont open new connection
        # per each request.
        # self.amount = amount
        async with ClientSession() as session:
            # pass Semaphore and session to every GET request
            found = False
            for emote in bttv_dict.keys():
                if emote == 'LXHeart':
                    found = True
                if found:
                    # if self.amount > 0:
                    url = self.bttvEmoteUrlStart + \
                        bttv_dict[emote]+self.bttvEmoteUrlEnd
                    task = asyncio.ensure_future(
                        self.bound_fetch(sem, url, session, emote))
                    tasks.append(task)
                # self.amount -= 1
                # else:
                #     break
                else:
                    print('Skipping {}'.format(emote))
            responses = asyncio.gather(*tasks)
            await responses
            print(responses)
Example #2
0
    async def run(cls):
        tasks = []
        json = FileHelper.JSONread('updated_emotes.json')
        sem = asyncio.Semaphore(500)
        async with ClientSession() as session:
            json_start = max(json.values())
            for image_id in range(json_start, 500000):
                # pass Semaphore and session to every GET request
                task = asyncio.ensure_future(
                    cls.bound_fetch(sem,
                                    cls.global_emotes_url.format(image_id),
                                    session, image_id))
                tasks.append(task)

            responses = asyncio.gather(*tasks)
            await responses
            for response in responses._result:
                if response is not None:
                    json[response[0]] = response[1]
            print(json)
            FileHelper.JSONwrite('updated_emotes.json', json)