Proxy support in workers and stuff

This commit is contained in:
Casey 2024-07-09 18:09:55 +03:00
parent a4bbe0434c
commit b1860ce065
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
4 changed files with 45 additions and 36 deletions

View File

@ -46,7 +46,7 @@ class App(tk.Tk):
ts = datetime.fromtimestamp(self._last_update / 1000)
path = ts.strftime(SCREENSHOTS_TMPL)
print("SAVED", path)
self._image.save(path)
self._image.save(path, lossless=True)
self.after(10000, self._save_image)

BIN
pictures/linus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -41,28 +41,12 @@
}
],
"elements": [
{
"type": "time",
"x": 75,
"y": 100,
"format": "And time is: %Y-%m-%d %H:%M:%S UTC",
"spf": 20,
"font": "/usr/share/fonts/TTF/TerminusTTF.ttf",
"size": 12
},
{
"type": "image",
"path": "../pictures/casey.png",
"x": 0,
"y": 128
},
{
"type": "animation",
"path": "../pictures/neko.gif",
"spf": 30,
"x": 625,
"y": 496
},
{
"type": "image",
"path": "../pictures/casey_qr.png",
@ -71,9 +55,15 @@
},
{
"type": "image",
"path": "../pictures/hueh.png",
"x": 490,
"y": 810
"x": 69,
"y": 112,
"path": "./thomas_adhd.png"
},
{
"type": "image",
"x": 69,
"y": 300,
"path": "./thomas_lain.png"
}
]
}

View File

@ -1,4 +1,5 @@
import functools
import json
from multiprocessing.shared_memory import SharedMemory
import asyncio
import random
@ -31,22 +32,25 @@ class WorkerManager:
self.n_toggles = 0
async def queue_manager(self):
index = random.randint(0, 999999)
offset = random.randint(0, 999999)
while True:
index = (index + 1) % 1000000
byte, bit = divmod(index, 8)
mask = 0x80 >> bit
for oy in [0, 4, 2, 6, 1, 3, 5, 7]:
for y in range(oy, 1000, 8):
for x in range(1000):
index = (x + y * 1000 + offset) % 1000000
byte, bit = divmod(index, 8)
mask = 0x80 >> bit
if self.shmem.buf[OFFSET_AVOID + byte] & mask:
continue
if self.shmem.buf[OFFSET_AVOID + byte] & mask:
continue
if (self.shmem.buf[OFFSET_MASK + byte] & mask) == 0:
continue
if (self.shmem.buf[OFFSET_MASK + byte] & mask) == 0:
continue
if (self.shmem.buf[OFFSET_CANVAS + byte] & mask) != (
self.shmem.buf[OFFSET_STATE + byte] & mask
):
await self.queue.put(index)
if (self.shmem.buf[OFFSET_CANVAS + byte] & mask) != (
self.shmem.buf[OFFSET_STATE + byte] & mask
):
await self.queue.put(index)
async def writer(self, bot_index: int, proxy: Optional[str] = None):
connector = ProxyConnector.from_url(proxy) if proxy else None
@ -105,14 +109,29 @@ class WorkerManager:
self.shmem.close()
async def main():
async with WorkerManager() as mgr:
async def main(config_path: str = "worker.json", *_):
with open(config_path, "r") as fp:
config = json.load(fp)
n_bots = config.get("n_bots", 1)
async with WorkerManager(config.get("shmem", "omcb-bot")) as mgr:
mgr.delay = config.get("delay", mgr.delay)
workers = []
if proxies := config.get("proxy", []):
workers.extend([mgr.writer(i, proxies[i % len(proxies)]) for i in range(n_bots)])
else:
workers.extend([mgr.writer(i) for i in range(n_bots)])
await asyncio.gather(
mgr.queue_manager(),
mgr.status_display(),
*[mgr.writer(i) for i in range(4)]
*workers
)
if __name__ == "__main__":
asyncio.run(main())
from sys import argv
asyncio.run(main(*argv[1:]))