-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduleout.py
executable file
·28 lines (24 loc) · 1.01 KB
/
scheduleout.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
"""Module that schedules a clock-out job using the platform-native job scheduler (Task Scheduler
on Windows, `at` on Mac/Linux).
"""
import subprocess
import os
def schedule(time: str) -> None:
"""Schedule a clock-out job at the specified time today. Clock-out will be executed at the
scheduled machine-local time.
Parameters:
* `time`: time string in HH:mm format.
Returns: None.
Side effects:
* Spawns subprocess.
* Adds job to OS job scheduler.
* Prints to standard output.
"""
if os.name == 'nt': # Use external PS script to add Task Scheduler task
print('Windows platform detected. Creating Task Scheduler task...')
subprocess.run(['powershell.exe', './scheduleout.ps1', time])
elif os.name == 'posix': # Invoke `at` directly
print('POSIX platform detected. Scheduling atjob...')
cmd = 'python3 autotimecalc.py out'
attime = time + ' today'
subprocess.run(['at', attime], input=cmd, encoding='utf-8')