-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcall_gcode_macro.py
31 lines (26 loc) · 929 Bytes
/
call_gcode_macro.py
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
import requests
import json
from datetime import datetime
# Configuration
macro_name = 'PRINT_END_SOUND'
moonraker_api_url = f'http://0.0.0.0:7125/printer/gcode/script?script={macro_name}'
# Get the current hour
current_hour = datetime.now().hour
# Check if the current time is not between 1 AM and 8 AM
if not (1 <= current_hour < 8):
# Send a request to Klipper to execute the macro
payload = {
"jsonrpc": "2.0",
"method": "printer.gcode.script",
"params": {
"script": f"{macro_name}"
},
"id": 7466}
try:
response = requests.post(moonraker_api_url, data=json.dumps(payload))
response.raise_for_status()
print(f'Successfully executed macro: {macro_name}')
except requests.exceptions.RequestException as e:
print(f'Failed to execute macro: {macro_name}. Error: {e}')
else:
print(f'Time is between 1 AM and 8 AM. Skipping macro execution.')