Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script gerador da foto oficial da Python Brasil 2020
import asyncio
import sys
from pathlib import Path
import discord
from PIL import Image
def gerar_imagem():
imagens = [
Image.open(foto).resize((100, 100), Image.ANTIALIAS)
for foto in Path("fotos").iterdir()
]
imagem_final = Image.new("RGB", (4800, 2800))
for x in range(0, 48):
for y in range(0, 28):
imagem_final.paste(imagens[(48 * y + x) % len(imagens)], (x * 100, y * 100))
imagem_final.save("python-brasil-2020.jpg")
async def salvar_imagem(member):
if member.default_avatar_url == member.avatar_url:
return
path = f"fotos/{member.id}.webp"
with open(path, "wb") as fp:
print(path)
await member.avatar_url.save(fp)
return path
async def main():
token = "Token do bot no Discord"
guild = "ID do servidor da Python Brasil"
client = discord.Client(intents=discord.Intents.all())
await client.login(token)
guild = await client.fetch_guild(guild)
members = await guild.fetch_members().flatten()
tarefas = [salvar_imagem(membro) for membro in membros]
# await asyncio.gather(*tarefas)
await client.close()
print("Imagens salvas")
gerar_imagem()
print("Imagem final gerada")
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.