athphane / userbot

with statements can be merged PTC-W0062
Anti-pattern
Major
6 months ago2 years old
Consider merging collapsible With statements`
21        headers = {"user-agent": "httpie"}
22        url = f"https://wttr.in/{location}?mnTC0&lang=en"
23        try:
24            async with aiohttp.ClientSession(headers=headers) as session:25                async with session.get(url) as resp:
26                    data = await resp.text()
27        except Exception:
Consider merging collapsible With statements`
20        await message.delete()
21        return
22
23    async with aiohttp.ClientSession() as session:24        async with session.get(
25                f"https://api.funtranslations.com/translate/yoda.json?text={txt}"
26        ) as resp:
Consider merging collapsible With statements`
12@UserBot.on_message(filters.command(["pat", "pats"], ".") & filters.me)
13async def give_pats(bot: UserBot, message: Message):
14    URL = "https://some-random-api.com/animu/pat"
15    async with aiohttp.ClientSession() as session:16        async with session.get(URL) as request:
17            if request.status == 404:
18                return await message.edit("`no Pats for you :c")
Consider merging collapsible With statements`
14async def paste(bot: UserBot, message: Message):
15    text = message.reply_to_message.text
16    try:
17        async with aiohttp.ClientSession() as session:18            async with session.post(
19                    "https://nekobin.com/api/documents", json={"content": text}, timeout=3
20            ) as response:
Consider merging collapsible With statements`
 4class Spacex:
 5    @staticmethod
 6    async def get(latest_or_next):
 7        async with aiohttp.ClientSession() as session: 8            async with session.get(
 9                f"https://api.spacexdata.com/v3/launches/{latest_or_next}"
10            ) as resp: