From 4adbb6088a0426c68dae499b51786c8e2716c973 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Thu, 3 Jun 2021 10:25:32 +0200 Subject: simple timing script --- setup | 5 +++++ time_to_go | 41 +++++++++++++++++++++++++++++++++++++++++ time_to_go_startup.service | 8 ++++++++ 3 files changed, 54 insertions(+) create mode 100755 setup create mode 100755 time_to_go create mode 100644 time_to_go_startup.service 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 -- cgit v1.2.3