Skip to content

Instantly share code, notes, and snippets.

@Higgs1
Last active March 17, 2021 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Higgs1/2a199ed8613b0ee7a4cad460e51bb266 to your computer and use it in GitHub Desktop.
Save Higgs1/2a199ed8613b0ee7a4cad460e51bb266 to your computer and use it in GitHub Desktop.
import atoot, aiohttp, PIL, io, asyncio
# access_token =
def gen_img(i):
img = PIL.Image.new('RGB', (500,500), (250,250,250))
draw = PIL.ImageDraw.Draw(img)
draw.text((75, -175), str(i), (0,0,0), PIL.ImageFont.truetype("OpenSans-Bold.ttf", 600))
file = io.BytesIO()
img.save(file, format= 'PNG')
file.seek(0)
return file
attachments = [gen_img(i) for i in range(4)] # critter.camp only allows a max of 4 piccies
print('Image gen is all done!')
async def upload_and_get_id(client, img_file):
idnum = int((await client.upload_attachment(img_file))['id'])
print('uploaded image', attachments.index(img_file), 'with id of', idnum)
return idnum
async with atoot.client('social.critter.camp', access_token = access_token) as client:
upload_jobs = [upload_and_get_id(client, img_file) for img_file in attachments]
attachment_ids = await asyncio.gather(*upload_jobs)
print('All piccies are done being uploaded')
await client.create_status({}, 'Test hewwo!', attachment_ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment