Пример #1
0
async def get(url: str, *args, **kwargs):
    async with session.get(url, *args, **kwargs) as resp:
        try:
            data = await resp.json()
        except Exception:
            data = await resp.text()
    return data
Пример #2
0
async def fetch(url: str):
    async with aiohttpsession.get(url, headers=headers) as resp:
        try:
            data = await resp.json()
        except Exception:
            data = await resp.text()
    return data
Пример #3
0
async def change_profile(_, message: Message):
    m = await eor(message, text="Anonymizing...")
    try:
        image_resp, name_resp = await gather(
            session.get("https://thispersondoesnotexist.com/image"),
            session.get("https://raw.githubusercontent.com/dominictarr/" +
                        "random-name/master/first-names.json"),
        )
        image = BytesIO(await image_resp.read())
        image.name = "a.png"
        name = choice(loads(await name_resp.text()))
        await gather(
            app2.set_profile_photo(photo=image),
            app2.update_profile(first_name=name),
        )
    except Exception as e:
        e = format_exc()
        err = await app.send_message(LOG_GROUP_ID, text=f"`{e}`")
        return await m.edit(f"**Error**: {err.link}")
    await m.edit(f"[Anonymized.](tg://user?id={USERBOT_ID})")
    image.close()
Пример #4
0
async def randomAudioFunc(answers: list, query: str) -> list:
    url = f"https://www.zedge.net/api-zedge-web/browse/search?query={query}&contentType=ringtones"
    async with aiohttpsession.get(url) as resp:
        data = await resp.json()
    items = data["items"]
    answers = [
        InlineQueryResultAudio(
            audio_url=audio["audioUrl"],
            thumb_url="https://tweety.drk1.workers.dev/0:/image_2021-05-22_20-56-47.png",
            title=audio["title"],
            mime_type="audio/mp3",
        )
        for audio in items
    ]
    return answers
async def download_url(
    url,
    file_path,
    chunk_size,
):
    file_path = file_path or url.split("/")[-1][:20]

    async with session.get(url) as response:
        ensure_status(response.status)

        async with aiofiles.open(file_path, "wb") as f:
            # Save content in file using aiohttp streamReader.
            async for chunk in response.content.iter_chunked(chunk_size):
                await f.write(chunk)

    return absolute_path(file_path)
Пример #6
0
async def download_song(url):
    async with session.get(url) as resp:
        song = await resp.read()
    song = BytesIO(song)
    song.name = "a.mp3"
    return song