Merge pull request #4 from kj7rrv/less-in-backend
Move parts of backends into new imgproc.py
This commit is contained in:
commit
87344df53e
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
|
server/pieces
|
||||||
|
server/newlist
|
||||||
|
server/oldlist
|
||||||
|
|
|
@ -1,48 +1,14 @@
|
||||||
import os
|
|
||||||
import requests
|
import requests
|
||||||
import threading
|
|
||||||
import json
|
|
||||||
|
|
||||||
def get_img():
|
def get_img():
|
||||||
raw_img = requests.get('http://localhost:8080/get_capture.bmp').content
|
raw_img = requests.get('http://localhost:8080/get_capture.bmp').content
|
||||||
|
|
||||||
with open('full_img.bmp', 'wb+') as f:
|
with open('img.bmp', 'wb+') as f:
|
||||||
f.write(raw_img)
|
f.write(raw_img)
|
||||||
|
|
||||||
os.system('convert full_img.bmp -resize 800x480 img.bmp')
|
return 'img.bmp'
|
||||||
|
|
||||||
with open('crops.json') as f:
|
|
||||||
crops = json.load(f)
|
|
||||||
|
|
||||||
threads = []
|
def touch(x, y, is_long):
|
||||||
for crop in crops:
|
|
||||||
threads.append(threading.Thread(target=os.system, args=(f'convert img.bmp -crop {crop} pieces/{crop.split("+", 1)[1].replace("+", "x")}.jpg',)))
|
|
||||||
threads[-1].start()
|
|
||||||
for thread in threads:
|
|
||||||
thread.join()
|
|
||||||
|
|
||||||
os.system("md5sum -c oldlist 2>/dev/null | grep FAILED > newlist")
|
|
||||||
changed = []
|
|
||||||
with open('newlist') as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
for line in lines:
|
|
||||||
changed.append(line.split(": ")[0].split('.')[0].split('/')[1])
|
|
||||||
os.system("md5sum pieces/* > oldlist")
|
|
||||||
return changed
|
|
||||||
|
|
||||||
def get_full_img():
|
|
||||||
raw_img = requests.get('http://localhost:8080/get_capture.bmp').content
|
|
||||||
|
|
||||||
with open('full_full.bmp', 'wb+') as f:
|
|
||||||
f.write(raw_img)
|
|
||||||
|
|
||||||
os.system('convert full_full.bmp -resize 800x480 full.jpg')
|
|
||||||
|
|
||||||
os.unlink('full_full.bmp')
|
|
||||||
|
|
||||||
return 'full.jpg'
|
|
||||||
|
|
||||||
def touch(x, y, w, is_long):
|
|
||||||
x = round(800 * x / w)
|
|
||||||
y = round(800 * y / w)
|
|
||||||
requests.get(f'http://localhost:8080/set_touch?x={x}&y={y}&hold={1 if is_long else 0}')
|
requests.get(f'http://localhost:8080/set_touch?x={x}&y={y}&hold={1 if is_long else 0}')
|
||||||
|
|
|
@ -1,41 +1,21 @@
|
||||||
import os
|
import os
|
||||||
import requests
|
|
||||||
import threading
|
import threading
|
||||||
import json
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def get_img():
|
|
||||||
os.system('xwd -root -silent | convert xwd:- img.bmp')
|
|
||||||
|
|
||||||
with open('crops.json') as f:
|
def _long_touch(x, y):
|
||||||
crops = json.load(f)
|
|
||||||
|
|
||||||
threads = []
|
|
||||||
for crop in crops:
|
|
||||||
threads.append(threading.Thread(target=os.system, args=(f'convert img.bmp -crop {crop} pieces/{crop.split("+", 1)[1].replace("+", "x")}.jpg',)))
|
|
||||||
threads[-1].start()
|
|
||||||
for thread in threads:
|
|
||||||
thread.join()
|
|
||||||
|
|
||||||
os.system("md5sum -c oldlist 2>/dev/null | grep FAILED > newlist")
|
|
||||||
changed = []
|
|
||||||
with open('newlist') as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
for line in lines:
|
|
||||||
changed.append(line.split(": ")[0].split('.')[0].split('/')[1])
|
|
||||||
os.system("md5sum pieces/* > oldlist")
|
|
||||||
return changed
|
|
||||||
|
|
||||||
def get_full_img():
|
|
||||||
os.system('xwd -root -silent | convert xwd:- full.jpg')
|
|
||||||
return 'full.jpg'
|
|
||||||
|
|
||||||
def touch(x, y, w, is_long):
|
|
||||||
x = round(800 * x / w)
|
|
||||||
y = round(800 * y / w)
|
|
||||||
if is_long:
|
|
||||||
os.system(f'xdotool mousemove {x} {y} mousedown 1')
|
os.system(f'xdotool mousemove {x} {y} mousedown 1')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
os.system(f'xdotool mouseup 1')
|
os.system(f'xdotool mouseup 1')
|
||||||
|
|
||||||
|
|
||||||
|
def get_img():
|
||||||
|
os.system('xwd -root -silent | convert xwd:- img.bmp')
|
||||||
|
return 'img.bmp'
|
||||||
|
|
||||||
|
|
||||||
|
def touch(x, y, is_long):
|
||||||
|
if is_long:
|
||||||
|
threading.Thread(target=_long_touch, args=(x, y,)).start()
|
||||||
else:
|
else:
|
||||||
os.system(f'xdotool mousemove {x} {y} click 1')
|
os.system(f'xdotool mousemove {x} {y} click 1')
|
||||||
|
|
42
server/imgproc.py
Normal file
42
server/imgproc.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import json
|
||||||
|
import threading
|
||||||
|
import os
|
||||||
|
|
||||||
|
def get_split_imgs():
|
||||||
|
bmp_path = backend.get_img()
|
||||||
|
|
||||||
|
with open('crops.json') as f:
|
||||||
|
crops = json.load(f)
|
||||||
|
|
||||||
|
threads = []
|
||||||
|
for crop in crops:
|
||||||
|
threads.append(threading.Thread(target=os.system, args=(f'convert {bmp_path} -crop {crop} pieces/{crop.split("+", 1)[1].replace("+", "x")}.jpg',)))
|
||||||
|
threads[-1].start()
|
||||||
|
for thread in threads:
|
||||||
|
thread.join()
|
||||||
|
|
||||||
|
os.unlink(bmp_path)
|
||||||
|
|
||||||
|
os.system("md5sum -c oldlist 2>/dev/null | grep FAILED > newlist")
|
||||||
|
changed = []
|
||||||
|
with open('newlist') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
for line in lines:
|
||||||
|
changed.append(line.split(": ")[0].split('.')[0].split('/')[1])
|
||||||
|
os.system("md5sum pieces/* > oldlist")
|
||||||
|
|
||||||
|
return changed
|
||||||
|
|
||||||
|
def get_full_img():
|
||||||
|
bmp_path = backend.get_img()
|
||||||
|
|
||||||
|
os.system(f'convert {bmp_path} img.jpg')
|
||||||
|
|
||||||
|
os.unlink(bmp_path)
|
||||||
|
|
||||||
|
return 'img.jpg'
|
||||||
|
|
||||||
|
def touch(x, y, w, is_long):
|
||||||
|
x = round(800 * x / w)
|
||||||
|
y = round(800 * y / w)
|
||||||
|
backend.touch(x, y, is_long)
|
|
@ -7,19 +7,21 @@ import time
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
from websocket_server import WebsocketServer
|
from websocket_server import WebsocketServer
|
||||||
|
import imgproc as hcapi
|
||||||
|
|
||||||
# Select backend - backends.port8080 uses HamClock's port 8080 service;
|
# Select backend - backends.port8080 uses HamClock's port 8080 service;
|
||||||
# backends.x11 uses an X11 server (typically Xvfb) (make sure DISPLAY is set
|
# backends.x11 uses an X11 server (typically Xvfb) (make sure DISPLAY is set
|
||||||
# correctly!)
|
# correctly!)
|
||||||
|
|
||||||
#import backends.port8080 as hcapi
|
#import backends.port8080 as backend
|
||||||
import backends.x11 as hcapi
|
import backends.x11 as backend
|
||||||
|
|
||||||
|
hcapi.backend = backend
|
||||||
|
|
||||||
|
|
||||||
def cycle():
|
def cycle():
|
||||||
try:
|
try:
|
||||||
changed = hcapi.get_img()
|
changed = hcapi.get_split_imgs()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
for client in clients.values():
|
for client in clients.values():
|
||||||
client.send('err%noconn%Server failed to capture screenshot', 'ERR')
|
client.send('err%noconn%Server failed to capture screenshot', 'ERR')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user