Skip to main content

A wrapper for the Discord Python Pixels API.

Project description

PyDisPix

A simple wrapper around Python Discord Pixels.

Requires Python 3.7+ (3.x where x >= 7).

Requires requests, pillow and matplotlib from pip.

Example

import pydispix

# Create a client with your token.
client = pydispix.Client('my-auth-token')

# Let pydispix find your token from `TOKEN` environmental variable
client = pydispix.Client()

# Fetch the canvas
canvas = client.get_canvas()

# Show the canvas using PIL
canvas.show()

# Show the canvas using matplotlib, this will include coordinates
canvas.mpl_show()

# Save the canvas to a file
canvas.save('canvas.png')

# And access pixels from it.
print(canvas[4, 10])

# Or just fetch a specific pixel.
print(client.get_pixel(4, 10))

# Draw a pixel.
client.put_pixel(50, 10, 'cyan')
client.put_pixel(1, 5, pydispix.Color.BLURPLE)
client.put_pixel(100, 4, '93FF00')
client.put_pixel(44, 0, 0xFF0000)
client.put_pixel(8, 54, (255, 255, 255))

We can also display the image with pillow

canvas = client.get_canvas()
canvas.show()

Or we can display with matplotlib to see it with coordinates

canvas = client.get_canvas()
canvas.mpl_show()

Auto-draw

Load an image:

from PIL import Image

im = Image.open('pretty.png')
ad = pydispix.AutoDrawer.load_image(client, (5, 40), im, scale=0.1)
ad.draw()

To prefer fixing existing pixels to placing new ones:

ad = pydispix.AutoDrawer.load(client, '''0
0
3
2
ff0000
00ff00
0000ff
ff0000
00ff00
0000ff''')
ad.draw()

Format of the drawing plan:

  • Leftmost X coordinate
  • Topmost Y coordinate
  • Width
  • Height
  • Each pixel, left-to-right, top-to-bottom.

Auto-draw will avoid colouring already correct pixels, for efficiency.

You can also run this continually with guard=True which makes sure that after your image is drawn, this keeps running to check if it haven't been tampered with, and fixes all non-matching pixels.

ad.draw(guard=True, guard_delay=2)

Guard delay is the delay between each full iteration of all pixels. We need to wait since looping without any changes is almost instant in python, and we don't want to put cpu through that stress for no reason

Churches

Churches are groups of people collaborating on some image, or set of images on the canvas. It's basically a big botnet of people. Most popular church is currently the Church Of Rick. Churches provide it's members with tasks to fill certain pixels, and the members finish those tasks and report it back to the church. This is how you run a single task like this with Church of Rick:

from pydispix.churches import RickChurchClient

client = RickChurchClient(pixels_api_token, rick_church_api_token)
client.run_task()

Church of SQLite is also supported, and they don't require an API key, it is free for everyone:

from pydispix.churches import SQLiteChurchClient

client = SQLiteChurchClient(pixels_api_token)
client.run_task()

You can also implement your own church according to it's specific API requirements, if you're interested in doing this, check the church.py and how the specific churches are implemented using it: churches.py.

Progress bars

Every request that has rate limits can now display a progress bar while it's sleeping on cooldown:

pixel = client.get_pixel(0, 0, show_progress=True)
canvas = client.get_canvas(show_progress=True)
client.put_pixel(52, 10, "FFFFFF", show_progress=True)

https://user-images.githubusercontent.com/20902250/119607092-418e4200-bde3-11eb-9ac5-4e455ffd47c2.mp4

Logging

To see logs, you can set the DEBUG environment variable, which changes the loglevel from logging.INFO to logging.DEBUG You can also do this manually by executing:

import logging

logger = logging.getLogger("pydispix")
logger.setLevel(logging.DEBUG)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydispix-0.6.7.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

pydispix-0.6.7-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file pydispix-0.6.7.tar.gz.

File metadata

  • Download URL: pydispix-0.6.7.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pydispix-0.6.7.tar.gz
Algorithm Hash digest
SHA256 7510d712eb89005cff45fd317d1cec4e4a8bf9aee0b30acb8b40f5cfb878e218
MD5 cfc95f98c578f86ce0829612a366129d
BLAKE2b-256 70e22a725c15d7912ce031b507a54ba008cae8ee890c11989aa57be2a8fe840e

See more details on using hashes here.

File details

Details for the file pydispix-0.6.7-py3-none-any.whl.

File metadata

  • Download URL: pydispix-0.6.7-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pydispix-0.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 469c8e706b270754ba67a3e13267cedfe0eca8fc15cc891d75caad304411d13e
MD5 a4e189b77a827be142a119964abdd037
BLAKE2b-256 b36bdbed700347121d3877722cfaadebe0402607f65c569d9a4744930f8a590f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page