Created
February 23, 2021 21:35
-
-
Save WitherOrNot/1318c7c2501b78127db3baac54f63300 to your computer and use it in GitHub Desktop.
pixelcanvas bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import numpy as np | |
from time import sleep | |
from PIL import Image | |
from requests import session | |
colors = [ | |
(255, 255, 255), | |
(228, 228, 228), | |
(136, 136, 136), | |
(34, 34, 34), | |
(255, 167, 209), | |
(229, 0, 0), | |
(229, 149, 0), | |
(160, 106, 66), | |
(229, 217, 0), | |
(148, 224, 68), | |
(2, 190, 1), | |
(0, 211, 221), | |
(0, 131, 199), | |
(0, 0, 234), | |
(207, 110, 228), | |
(130, 0, 128), | |
] | |
palette = sum([[x,y,z] for x,y,z in colors], []) + [0,0,0] * 240 | |
fingerprint = sys.argv[4] | |
def quantize(image): | |
pal_image = Image.new("P", (1,1)) | |
pal_image.putpalette(palette) | |
q = image.quantize(palette=pal_image, method=Image.MAXCOVERAGE) | |
return q.convert("RGB") | |
def draw_pixel(x, y, i): | |
payload = f'{{"x":{xs+x},"y":{ys+y},"color":{i},"fingerprint":"{fingerprint}","token":null,"wasabi":{xs+x+ys+y+2342}}}' | |
stat = 400 | |
while stat != 200: | |
resp = sess.post( | |
"https://europe-west1-pixelcanvasv2.cloudfunctions.net/pixel", | |
headers={ | |
"Accept": "*/*", | |
"Accept-Encoding": "gzip, deflate, br", | |
"Accept-Language": "en-US,en;q=0.9", | |
"Content-Length": str(len(payload)), | |
"Content-Type": "application/json", | |
"Origin": "https://pixelcanvas.io", | |
"Referer": f"https://pixelcanvas.io/@{xs+x},{ys+y}", | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36" | |
}, | |
data=payload | |
) | |
stat = resp.status_code | |
wait = resp.json()["waitSeconds"] | |
if stat != 200: | |
print(f"Got status code {stat}, waiting 3 seconds") | |
sleep(3) | |
return wait | |
raw = Image.open(sys.argv[1]).convert("RGBA") | |
img = Image.new("RGB", raw.size) | |
rd = raw.getdata() | |
nd = [x[:-1] if x[-1] == 255 else (255,255,255) for x in rd] | |
img.putdata(nd) | |
xs, ys = int(sys.argv[2]), int(sys.argv[3]) | |
sess = session() | |
sess.post("https://europe-west1-pixelcanvasv2.cloudfunctions.net/me", json={"fingerprint": fingerprint}) | |
qzi = quantize(img) | |
for y in range(qzi.height): | |
for x in range(qzi.width): | |
px = qzi.getpixel((x,y)) | |
if px == (255,255,255): | |
continue | |
index = colors.index(px) | |
wait = draw_pixel(x, y, index) | |
print(f"Drew @{xs+x},{ys+y} with color {index}, waiting {wait} seconds") | |
sleep(wait) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment