This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresent.py
More file actions
executable file
·72 lines (62 loc) · 1.73 KB
/
present.py
File metadata and controls
executable file
·72 lines (62 loc) · 1.73 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# To install dependencies:
# pip3 install requests sseclient-py pyautogui
import argparse
import json
import requests
import sseclient
import time
import urllib
ALLOWED_CONTROLS = {'left', 'right'}
parser = argparse.ArgumentParser(description='slidetogether.io presenter client')
parser.add_argument('url')
parser.add_argument('--keynote', action='store_true')
args = parser.parse_args()
url = urllib.parse.urlparse(args.url)
qs = urllib.parse.parse_qs(url.query)
if 'room' not in qs or len(qs['room']) != 1:
print(f'invalid url: {args.url}')
room = qs['room'][0]
presentUrl = urllib.parse.urlunparse([
url.scheme,
url.netloc,
url.path + 'api/present',
url.params,
urllib.parse.urlencode({'room_id': room}),
url.fragment,
])
if args.keynote:
import subprocess
LOOKUP = {
'left': 'show previous',
'right': 'show next',
}
def send_key(key):
subprocess.run([
'osascript',
'-e', 'tell application "Keynote"',
'-e', LOOKUP[key],
'-e', 'end tell',
])
else:
import pyautogui
pyautogui.FAILSAFE = False
def send_key(key):
pyautogui.press(control)
while True:
try:
response = requests.get(presentUrl, stream=True)
client = sseclient.SSEClient(response)
for event in client.events():
parsed = json.loads(event.data)
control = parsed['control']
if control == '':
continue
if control not in ALLOWED_CONTROLS:
print(f'INVALID CONTROL: {control}')
continue
print(control)
send_key(control)
except Exception as e:
print(e)
time.sleep(2)