Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import websocket, time, random, json
- from proxylist import ProxyList
- import numpy as np
- from struct import *
- from urllib import request as urlrequest
- class Tile:
- color = 0
- isBusy = False
- isCompleted = False
- def __init__(self, color=0):
- self.color = color
- def IniciarTiles():
- tiles = np.empty(shape=(4000,4000), dtype='object')
- tiles.fill(Tile())
- return tiles
- def IniciarConfiguracion():
- tiles = np.empty(shape=(4000,4000), dtype='object')
- tiles[1121, 3162] = Tile(4)
- tiles[1121, 3163] = Tile(4)
- tiles[1121, 3164] = Tile(4)
- tiles[1121, 3165] = Tile(4)
- tiles[1121, 3166] = Tile(4)
- tiles[1121, 3167] = Tile(4)
- tiles[1121, 3168] = Tile(4)
- tiles[1121, 3169] = Tile(4)
- tiles[1121, 3170] = Tile(4)
- tiles[1121, 3171] = Tile(4)
- tiles[1121, 3172] = Tile(4)
- tiles[1121, 3173] = Tile(4)
- tiles[1121, 3174] = Tile(4)
- tiles[1121, 3175] = Tile(4)
- tiles[1121, 3176] = Tile(4)
- tiles[1121, 3177] = Tile(4)
- return tiles
- def BuscarTile(tilesPintar):
- for (x,y), value in np.ndenumerate(tilesPintar):
- #No Existe, paso
- if not value:
- continue
- #Está listo
- if value.isCompleted:
- continue
- #No está ocupado
- if not value.isBusy:
- return {'x': x, 'y': y, 'value': value}
- return False
- def Pintar(host, port):
- while(1):
- #Debug
- #websocket.enableTrace(True)
- url = 'http://pixelcanvas.io/api/ws'
- req = urlrequest.Request(url, data=None,
- headers={
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
- })
- response = urlrequest.urlopen(req)
- data = response.read()
- encoding = response.info().get_content_charset('utf-8')
- ws_url = json.loads(data.decode(encoding))
- websocket.setdefaulttimeout(600)
- ws = websocket.WebSocket()
- try:
- ws.connect(ws_url['url'], header=["Origin: http://pixelcanvas.io", "Pragma: no-cache", "Cache-Control: no-cache", "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", "Accept-Encoding: gzip, deflate, sdch", "Accept-Language: es-ES,es;q=0.8"])
- except:
- print("Error en Socket %s:%s"% (host, port))
- return
- target = BuscarTile(tilesPintar)
- if not target:
- print("No quedan más target, thread finalizado")
- return
- target['value'].isBusy = True
- print("Pintando con: %s:%s, Target %d-%d "% (host, port, target['x'], target['y']))
- posx = target['x']
- posy = target['y']
- color = target['value'].color
- posxHex = posx.to_bytes(2, 'big')
- posyHex = posy.to_bytes(2, 'big')
- colorHex = color.to_bytes(1, 'big')
- t = 1
- for i in range(4):
- t += 1
- timeHex = t.to_bytes(1, 'big')
- ws.send_binary("\x75\x00"+timeHex.decode())
- time.sleep(1)
- ws.send_binary("\x01"+posxHex.decode()+posyHex.decode()+colorHex.decode())
- #01 04 41 0c 49 03
- #01 = ID PAQ
- #04 41 = PosX
- #0c 40 = PosY
- #03 = Color
- #ws.send_binary("\x01"+posxHex.decode()+posyHex.decode()+colorHex.decode())
- ws.close()
- target['value'].isBusy = False
- target['value'].isCompleted = True
- print("Esperando 140 segundos")
- time.sleep(140)
- def IniciarThreads():
- for val in pl:
- threading.Thread(None, Pintar, None, (val.host, val.port), None).start()
- def CLI():
- while(1):
- i = input("Ingrese opcion (q=Salir): ")
- if "q" in i:
- exit()
- else:
- time.sleep(1)
- continue
- print("Cargando Tiles")
- tiles = IniciarTiles()
- print("Cargando Tiles a rellenar")
- tilesPintar = IniciarConfiguracion()
- print("Iniciando Threads")
- IniciarThreads()
- #CLI()
Advertisement
Add Comment
Please, Sign In to add comment