Skip to content

Instantly share code, notes, and snippets.

@rougeth
Created November 8, 2020 21:06
Show Gist options
  • Save rougeth/0342f2982472323569cbe7fbf73be474 to your computer and use it in GitHub Desktop.
Save rougeth/0342f2982472323569cbe7fbf73be474 to your computer and use it in GitHub Desktop.
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