Repository navigation
Expand file tree
/
Copy pathscript.py
More file actions
58 lines (38 loc) · 1.37 KB
/
Copy pathscript.py
File metadata and controls
58 lines (38 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import requests
import pyautogui
import time
import os
from datetime import datetime
ESP_IP = "10.251.100.160" # replace with your ESP IP
SAVE_FOLDER = r"/home/pritha/ptt"
os.makedirs(SAVE_FOLDER, exist_ok=True)
last_state = None
last_shot = False
while True:
try:
response = requests.get(f"http://{ESP_IP}/data", timeout=2)
data = response.text.strip()
print("Received:", data)
# ===== PLAY / PAUSE =====
if data == "PAUSE" and last_state != "PAUSE":
pyautogui.press("space")
last_state = "PAUSE"
elif data == "PLAY" and last_state != "PLAY":
pyautogui.press("space")
last_state = "PLAY"
# ===== SCREENSHOT =====
elif data == "SHOT" and not last_shot:
filename = datetime.now().strftime("screenshot_%Y%m%d_%H%M%S.png")
filepath = os.path.join(SAVE_FOLDER, filename)
img = pyautogui.screenshot() # capture
img.save(filepath) # explicit write
print(f"Saved at: {filepath}")
print("File exists?", os.path.exists(filepath))
last_shot = True
elif data != "SHOT":
last_shot = False
except requests.exceptions.RequestException as e:
print("ESP connection error:", e)
except Exception as e:
print("Other error:", e)
time.sleep(0.2)