-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
|
||
<plist version="1.0"> | ||
|
||
<dict> | ||
<key>Label</key> | ||
<string>com.jaraco.home.trap-watcher</string> | ||
<key>ProgramArguments</key> | ||
<array> | ||
<string>{sys.executable}</string> | ||
<string>-m</string> | ||
<string>jaraco.home.trap-watcher</string> | ||
</array> | ||
<key>StartInterval</key> | ||
<integer>3600</integer> | ||
<key>SessionCreate</key> | ||
<false/> | ||
<key>StandardErrorPath</key> | ||
<string>{logs}/trap-watcher.err</string> | ||
<key>StandardOutPath</key> | ||
<string>{logs}/trap-watcher.out</string> | ||
</dict> | ||
|
||
</plist> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import asyncio | ||
import pathlib | ||
import subprocess | ||
import sys | ||
|
||
import keyring | ||
import rumps | ||
import typer | ||
import victor_smart_kill as vsk | ||
|
||
from . import contact | ||
from .compat.py38 import resources | ||
|
||
|
||
app = typer.Typer() | ||
|
||
|
||
async def check_traps(): | ||
username = contact.load().email | ||
password = keyring.get_password('https://www.victorpest.com', username) | ||
async with vsk.VictorAsyncClient(username, password) as client: | ||
api = vsk.VictorApi(client) | ||
traps = await api.get_traps() | ||
return any(trap.status for trap in traps) | ||
|
||
|
||
class TrapWatch: | ||
def __init__(self): | ||
self.app = rumps.App("Traps", icon=self.icon) | ||
rumps.Timer(self.check_traps, 3600).start() | ||
self.app.run() | ||
|
||
def check_traps(self, timer): | ||
if asyncio.run(check_traps()): | ||
rumps.notification( | ||
"Smart Traps", | ||
subtitle=None, | ||
message="Check the traps.", | ||
img=self.icon, | ||
) | ||
|
||
@property | ||
def icon(self): | ||
return str(resources.files() / 'mouse.png') | ||
|
||
|
||
@app.command() | ||
def install(): | ||
name = 'Trap Watcher.plist' | ||
agents = pathlib.Path('~/Library/LaunchAgents').expanduser() | ||
target = agents / name | ||
tmpl = resources.files().joinpath(name).read_text() | ||
logs = pathlib.Path(sys.executable).parent.parent / 'logs' | ||
source = tmpl.format(sys=sys, logs=logs) | ||
target.write_text(source) | ||
subprocess.check_output(['launchctl', 'load', target]) | ||
|
||
|
||
@app.callback(invoke_without_command=True) | ||
def main(ctx: typer.Context, update: bool = False): | ||
if ctx.invoked_subcommand: | ||
return | ||
TrapWatch() | ||
|
||
|
||
__name__ == '__main__' and app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added an app to watch the traps. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters