barebones break timer that only continues with user input
This commit is contained in:
parent
bae5ebda48
commit
3e69c99523
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "breakscreen"
|
||||||
|
version = "0.1.0"
|
98
main.py
Executable file
98
main.py
Executable file
|
@ -0,0 +1,98 @@
|
||||||
|
#! /usr/bin/env python3
|
||||||
|
# vim:fenc=utf-8
|
||||||
|
#
|
||||||
|
# Copyright © 2023 gum <gum@gums-lappy>
|
||||||
|
#
|
||||||
|
# Distributed under terms of the MIT license.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Play my playlist every few minutes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from select import select
|
||||||
|
from subprocess import DEVNULL, Popen, run
|
||||||
|
from termios import TCIOFLUSH, tcflush
|
||||||
|
from time import sleep, time
|
||||||
|
|
||||||
|
|
||||||
|
class StoppableThread(threading.Thread):
|
||||||
|
"""Thread class with a stop() method. The thread itself has to check
|
||||||
|
regularly for the stopped() condition."""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(StoppableThread, self).__init__(*args, **kwargs)
|
||||||
|
self._stop_event = threading.Event()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._stop_event.set()
|
||||||
|
|
||||||
|
def stopped(self):
|
||||||
|
return self._stop_event.is_set()
|
||||||
|
|
||||||
|
|
||||||
|
def generate_interval(interval: int):
|
||||||
|
"""
|
||||||
|
Generate the interval between plays in seconds.
|
||||||
|
"""
|
||||||
|
if interval:
|
||||||
|
while True:
|
||||||
|
yield int(interval)
|
||||||
|
else:
|
||||||
|
# pomodoro scheme
|
||||||
|
while True:
|
||||||
|
yield 60 * 25
|
||||||
|
for _ in range(3):
|
||||||
|
yield 60 * 5
|
||||||
|
yield 60 * 25
|
||||||
|
yield 60 * 30
|
||||||
|
|
||||||
|
|
||||||
|
def play_playlist(playlist):
|
||||||
|
"""
|
||||||
|
Play the playlist.
|
||||||
|
"""
|
||||||
|
return Popen(
|
||||||
|
["mpv", "--shuffle", "--no-video", playlist], stdout=DEVNULL, stderr=DEVNULL
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_or_enter(duration, i3_focus=False):
|
||||||
|
stop = ""
|
||||||
|
start = time()
|
||||||
|
while not stop and (time() - start < duration): # Run until flag is True
|
||||||
|
if i3_focus:
|
||||||
|
run(["i3-msg", '[title=\"break\"] focus'])
|
||||||
|
stop, _, _ = select([sys.stdin], [], [], 1)
|
||||||
|
tcflush(sys.stdin, TCIOFLUSH)
|
||||||
|
|
||||||
|
|
||||||
|
def main(playlist, interval):
|
||||||
|
for i in generate_interval(interval):
|
||||||
|
play = play_playlist(playlist)
|
||||||
|
print(f"playlist playing, press enter to start {i // 60} minute interval")
|
||||||
|
wait_or_enter(float("inf"), i3_focus=True)
|
||||||
|
play.terminate()
|
||||||
|
print("...")
|
||||||
|
wait_or_enter(i)
|
||||||
|
print("next")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"--playlist",
|
||||||
|
default="/mnt/nas/m/m/anime-muziek",
|
||||||
|
help="path to the folder with the playlist to play",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--interval",
|
||||||
|
default=None,
|
||||||
|
type=str,
|
||||||
|
help="Interval between plays in minutes, if empty I use the pomodoro scheme.",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main(args.playlist, args.interval)
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pyright
|
Loading…
Reference in New Issue
Block a user