commit
a37a94e505
4 changed files with 229 additions and 0 deletions
-
115.gitignore
-
39clicker_control.py
-
12client.py
-
63server.py
@ -0,0 +1,115 @@ |
|||||
|
# Byte-compiled / optimized / DLL files |
||||
|
__pycache__/ |
||||
|
*.py[cod] |
||||
|
*$py.class |
||||
|
|
||||
|
# C extensions |
||||
|
*.so |
||||
|
|
||||
|
# Distribution / packaging |
||||
|
.Python |
||||
|
build/ |
||||
|
develop-eggs/ |
||||
|
dist/ |
||||
|
downloads/ |
||||
|
eggs/ |
||||
|
.eggs/ |
||||
|
lib/ |
||||
|
lib64/ |
||||
|
parts/ |
||||
|
sdist/ |
||||
|
var/ |
||||
|
wheels/ |
||||
|
share/python-wheels/ |
||||
|
*.egg-info/ |
||||
|
.installed.cfg |
||||
|
*.egg |
||||
|
MANIFEST |
||||
|
|
||||
|
# PyInstaller |
||||
|
# Usually these files are written by a python script from a template |
||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it. |
||||
|
*.manifest |
||||
|
*.spec |
||||
|
|
||||
|
# Installer logs |
||||
|
pip-log.txt |
||||
|
pip-delete-this-directory.txt |
||||
|
|
||||
|
# Unit test / coverage reports |
||||
|
htmlcov/ |
||||
|
.tox/ |
||||
|
.nox/ |
||||
|
.coverage |
||||
|
.coverage.* |
||||
|
.cache |
||||
|
nosetests.xml |
||||
|
coverage.xml |
||||
|
*.cover |
||||
|
.hypothesis/ |
||||
|
.pytest_cache/ |
||||
|
|
||||
|
# Translations |
||||
|
*.mo |
||||
|
*.pot |
||||
|
|
||||
|
# Django stuff: |
||||
|
*.log |
||||
|
local_settings.py |
||||
|
db.sqlite3 |
||||
|
|
||||
|
# Flask stuff: |
||||
|
instance/ |
||||
|
.webassets-cache |
||||
|
|
||||
|
# Scrapy stuff: |
||||
|
.scrapy |
||||
|
|
||||
|
# Sphinx documentation |
||||
|
docs/_build/ |
||||
|
|
||||
|
# PyBuilder |
||||
|
target/ |
||||
|
|
||||
|
# Jupyter Notebook |
||||
|
.ipynb_checkpoints |
||||
|
|
||||
|
# IPython |
||||
|
profile_default/ |
||||
|
ipython_config.py |
||||
|
|
||||
|
# pyenv |
||||
|
.python-version |
||||
|
|
||||
|
# celery beat schedule file |
||||
|
celerybeat-schedule |
||||
|
|
||||
|
# SageMath parsed files |
||||
|
*.sage.py |
||||
|
|
||||
|
# Environments |
||||
|
.env |
||||
|
.venv |
||||
|
env/ |
||||
|
venv/ |
||||
|
ENV/ |
||||
|
env.bak/ |
||||
|
venv.bak/ |
||||
|
|
||||
|
# Spyder project settings |
||||
|
.spyderproject |
||||
|
.spyproject |
||||
|
|
||||
|
# Rope project settings |
||||
|
.ropeproject |
||||
|
|
||||
|
# mkdocs documentation |
||||
|
/site |
||||
|
|
||||
|
# mypy |
||||
|
.mypy_cache/ |
||||
|
.dmypy.json |
||||
|
dmypy.json |
||||
|
|
||||
|
# Pyre type checker |
||||
|
.pyre/ |
||||
@ -0,0 +1,39 @@ |
|||||
|
import psutil |
||||
|
import pyautogui as send_input |
||||
|
import subprocess |
||||
|
import os |
||||
|
CLICKER_START_COM = os.path.expandvars('"%userprofile%\Documents\clickerP.exe" 20') |
||||
|
class clicker_manager: |
||||
|
def __init__(self): |
||||
|
self.proc_id = None |
||||
|
for process in psutil.process_iter(): |
||||
|
if process.name() == 'clickerP.exe': |
||||
|
self.proc_id = process.pid |
||||
|
break |
||||
|
print(self.proc_id) |
||||
|
if self.proc_id is None: |
||||
|
self.proc_id = subprocess.Popen(CLICKER_START_COM).pid |
||||
|
self.on = False |
||||
|
def toggle(self): |
||||
|
send_input.press('tab') |
||||
|
self.on = not self.on |
||||
|
|
||||
|
def turn_off(self): |
||||
|
if self.on: |
||||
|
self.toggle() |
||||
|
|
||||
|
|
||||
|
def turn_on(self): |
||||
|
if not self.on: |
||||
|
self.toggle() |
||||
|
|
||||
|
def kill(self): |
||||
|
try: |
||||
|
proc = psutil.Process(self.proc_id) |
||||
|
for sub_proc in proc.children(recursive=True): |
||||
|
sub_proc.kill() |
||||
|
proc.kill() |
||||
|
except psutil.NoSuchProcess: |
||||
|
pass |
||||
|
if __name__ == "__main__": |
||||
|
test = clicker_manager() |
||||
@ -0,0 +1,12 @@ |
|||||
|
import argparse |
||||
|
import requests |
||||
|
if __name__ == "__main__": |
||||
|
parser = argparse.ArgumentParser() |
||||
|
parser.add_argument('host',default = "localhost:5138",nargs='?') |
||||
|
parser.add_argument('action',choices = ['on','off','toggle','kill']) |
||||
|
args = parser.parse_args() |
||||
|
r = requests.post('http://{host}?action={action}'.format(**args.__dict__)) |
||||
|
if r.status_code == 204: |
||||
|
print('server killed') |
||||
|
else: |
||||
|
print(r.text) |
||||
@ -0,0 +1,63 @@ |
|||||
|
from clicker_control import clicker_manager |
||||
|
from http import server |
||||
|
from threading import Thread |
||||
|
from urllib.parse import urlparse,parse_qs |
||||
|
import argparse |
||||
|
import json |
||||
|
|
||||
|
class handler(server.BaseHTTPRequestHandler): |
||||
|
def do_POST(self): |
||||
|
params = parse_qs(urlparse(self.path).query) |
||||
|
action = params['action'][0] |
||||
|
print(action) |
||||
|
ret = {} |
||||
|
if action == 'on': |
||||
|
self.server.manager.turn_on() |
||||
|
ret['status'] = 'on' |
||||
|
elif action == 'off': |
||||
|
self.server.manager.turn_off() |
||||
|
ret['status'] = 'off' |
||||
|
elif action == 'toggle': |
||||
|
self.server.manager.toggle() |
||||
|
if self.server.manager.on: |
||||
|
ret['status'] = 'on' |
||||
|
else: |
||||
|
ret['status'] = 'off' |
||||
|
elif action == 'kill': |
||||
|
self.server.manager.kill() |
||||
|
self.send_response(204) |
||||
|
self.end_headers() |
||||
|
print('server being killed') |
||||
|
self.server.serve = False |
||||
|
return |
||||
|
else: |
||||
|
self.send_response(400) |
||||
|
self.end_headers() |
||||
|
resp = "Action not recognized".encode() |
||||
|
self.wfile.write(resp) |
||||
|
return |
||||
|
self.send_response(201) |
||||
|
self.end_headers() |
||||
|
resp = json.dumps(ret).encode() |
||||
|
self.wfile.write(resp) |
||||
|
|
||||
|
class clicker_server(server.HTTPServer): |
||||
|
def __init__(self,location): |
||||
|
self.manager = clicker_manager() |
||||
|
self.serve = True |
||||
|
super().__init__(location,handler) |
||||
|
|
||||
|
def serve_forever(self): |
||||
|
while self.serve: |
||||
|
self.handle_request() |
||||
|
self.socket.close() |
||||
|
|
||||
|
def start_server(hostname,port): |
||||
|
httpd = clicker_server((hostname,args.port)) |
||||
|
httpd.serve_forever() |
||||
|
|
||||
|
if __name__ == "__main__": |
||||
|
parser = argparse.ArgumentParser() |
||||
|
parser.add_argument('-p','--port',type=int,default=5138) |
||||
|
args = parser.parse_args() |
||||
|
start_server('localhost',args.port) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue