summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsetup5
-rwxr-xr-xtime_to_go41
-rw-r--r--time_to_go_startup.service8
3 files changed, 54 insertions, 0 deletions
diff --git a/setup b/setup
new file mode 100755
index 0000000..5a98b6e
--- /dev/null
+++ b/setup
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+loginctl enable-linger tom
+cp time_to_go_startup.service ~/.config/systemd/user/
+systemctl --user enable time_to_go_startup
diff --git a/time_to_go b/time_to_go
new file mode 100755
index 0000000..e0507c7
--- /dev/null
+++ b/time_to_go
@@ -0,0 +1,41 @@
+#!/bin/python
+from os import path
+from sys import argv
+from datetime import datetime, timedelta
+from pickle import dump, load
+
+arrival_path = "/home/tom/work/.arrival"
+now = datetime.now()
+
+
+def update_arrival(dt):
+ with open(arrival_path, "wb") as arrival_file:
+ dump(dt, arrival_file)
+
+
+def get_arrival():
+ with open(arrival_path, "rb") as arrival_file:
+ return load(arrival_file)
+
+
+if len(argv) > 1:
+ update_arrival(
+ datetime.strptime(argv[1], "%H:%M").replace(
+ day=now.day, month=now.month, year=now.year
+ )
+ )
+
+if path.isfile(arrival_path):
+ potential_arrival = get_arrival()
+
+ if potential_arrival.date() < now.date():
+ update_arrival(now)
+
+ arrival = get_arrival()
+
+ time_to_leave = arrival + timedelta(hours=8, minutes=40)
+
+ print(str(time_to_leave - now).split(".")[0])
+
+else:
+ update_arrival(now)
diff --git a/time_to_go_startup.service b/time_to_go_startup.service
new file mode 100644
index 0000000..ddb463f
--- /dev/null
+++ b/time_to_go_startup.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Launch time_to_go at boot
+
+[Service]
+ExecStart=/home/tom/bin/time_to_go
+
+[Install]
+WantedBy=default.target