junepark678 / GIRRewrite

with statements can be merged PTC-W0062
Anti-pattern
Major
a year agoa year old
Consider merging collapsible With statements`
454                raise commands.BadArgument("That command is on cooldown.")
455
456        await ctx.defer(ephemeral=False)
457        async with aiohttp.ClientSession(headers={"Authorization": f"Bearer {cfg.open_ai_token}", "Content-Type": "application/json"}) as client:458            async with client.post(f"https://api.openai.com/v1/engines/text-davinci-001/completions", json={
459                "prompt": prompt,
460                "temperature": 0.7,
Consider merging collapsible With statements`
279
280    @cached(ttl=3600)
281    async def fetch_cij_or_news_database(self):
282        async with aiohttp.ClientSession() as session:283            async with session.get("https://raw.githubusercontent.com/DiscordGIR/CIJOrNewsFilter/main/database.json") as resp:
284                if resp.status == 200:
285                    data = await resp.text()
Consider merging collapsible With statements`
51
52    @cached(ttl=3600)
53    async def get_tiktok_redirect(self, link: str):
54        async with aiohttp.ClientSession() as session:55            async with session.get(link, allow_redirects=False) as response:
56                if response.status != 301:
57                    return
Consider merging collapsible With statements`
157
158    @staticmethod
159    async def do_content_parsing(url):
160        async with aiohttp.ClientSession() as session:161            async with session.head(url) as resp:
162                if resp.status != 200:
163                    return None
Consider merging collapsible With statements`
 5
 6async def emoji_thing():
 7    emojis = None
 8    async with aiohttp.ClientSession() as client: 9        async with client.get('https://unicode.org/emoji/charts/full-emoji-list.html') as resp:
10            assert resp.status == 200
11            soup = BeautifulSoup(await resp.text(), 'html.parser')