You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

11 months ago
import requests
from time import sleep
# Progress-bar
11 months ago
from tqdm import tqdm
# Work with list-like objects
from listwork import *
# Easy debug
from icecream import ic
11 months ago
ic.disable() # Disable debug
11 months ago
global server
#server = 'http://127.0.0.1:3333'
server = 'http://pb.gulyaipole.fun'
# fill(0,0, 10,10, [0,0,0])
11 months ago
def fill(x1,y1, x2,y2, color):
pxls = []
r = color[0] ; g = color[1] ; b = color[2]
for x in range(x1, x2+1):
for y in range(y1, y2+1):
pxls.append([x, y, r, g, b])
return pxls
# draw( fill(...), limit=500, token="fdsfs" )
11 months ago
def draw(pxls, limit=300, token="None"):
11 months ago
global server
ic(pxls)
push = [] # Push %limit% items
while len(pxls) > limit:
packs = [] # Merge elements to %limit% size list
for i in range(limit):
# Take first element
11 months ago
packs.append(pxls[0])
pxls.pop(0)
push.append({"main": pack(packs), "token": token})
push.append({"main": pack(pxls), "token": token}) # Pack last
11 months ago
ic(push)
11 months ago
for i in tqdm(push):
response = requests.post(server, i)
while not response.status_code == 200:
11 months ago
print("Error, retrying...")
response = requests.post(server, i)
sleep(0.1)
11 months ago
11 months ago
# cfill(0,0, 10,10) // Limit - 34x34
11 months ago
def cfill(x1,y1, x2,y2):
pxls = []
for x in range(x1, x2+1):
for y in range(y1, y2+1):
pxls.append([x, y])
packed = pack(pxls)
return packed
# ccheck( packed([[0,0]]) ) or ccheck(cfill(...))
def ccheck(packed):
global server
response = requests.get(f'{server}/get_color={packed}')
11 months ago
ic(response.text)
11 months ago
out = unpack(response.text)
return out
11 months ago
### EXAMPLE
# Draw random square 100x100 on 0,0
11 months ago
from random import randint as ri
11 months ago
draw( fill(0,0, 100,100, [ri(0,255),ri(0,255),ri(0,255)]) )
11 months ago
11 months ago
# Check square 34x34 on 0,0
print(ccheck(cfill(0,0, 34,34)))
11 months ago
11 months ago
# Use extras, draw 1/2 random square 100x100 on 0,0
from bot_extras import *
draw(pas2( rand(0,0, 100,100) ))
# Draw image (flipped (BUG) )
from im_convert import *
image = convert("example.png", [10,0])
from remove_back import *
draw( optimize(image, [255,255,255]) ) # Remove white background and draw
11 months ago
# Draw with premium-token, limit 600 (default token)
# Token is fake, >ERROR<
11 months ago
draw( fill(758,0, 1123,198, [255,255,255]), limit=600, token="3744138bd462cd8180e4w3534rfdsw4rwert" )