dotfiles

A steaming hot pile of sh...ell scripts and configuration files.
git clone https://kaka.farm/~git/dotfiles
Log | Files | Refs

meditate (1753B)


      1 #!/usr/bin/env python3
      2 
      3 """Meditate.
      4 
      5 Usage:
      6   meditate [options]
      7            <--bell=PATH>
      8            [--session-time=TIME]
      9            [--interval-time=TIME]
     10 
     11 Options:
     12   -h --help
     13   --usage
     14   -v --verbose
     15   --session-time=TIME  Total meditation session time. [default: 1200]
     16   --interval-time=TIME  Length of each interval in seconds. [default: 300]
     17 """
     18 
     19 
     20 import logging
     21 import multiprocessing
     22 import os
     23 import pathlib
     24 import subprocess
     25 
     26 import attr
     27 
     28 import docopt
     29 
     30 
     31 logger = logging.getLogger(__name__)
     32 
     33 
     34 @attr.s
     35 class Session:
     36     demarcation_sound_path: os.PathLike
     37     interval_sound_path: os.PathLike
     38     interval_time: float = attr.ib(default=20. * 60)
     39     session_time: float = attr.ib(default=60. * 60)
     40 
     41     @staticmethod
     42     def play_sound(sound_path):
     43         subprocess.Popen(["mpv", sound_path])
     44 
     45     def play_demarcation_sound(self):
     46         self.play_sound(self.demarcation_sound_path)
     47 
     48     def play_interval_sound(self):
     49         self.play_sound(self.interval_sound_path)
     50 
     51     def meditate(self) -> None:
     52         self.play_demarcation_sound()
     53 
     54 
     55 def main():
     56     print("Start meditating.")
     57 
     58     arguments = docopt.docopt(__doc__)
     59 
     60     interval_time = float(arguments.get("--interval"))
     61     session_time = float(arguments.get("--session-time"))
     62     interval_sound_path = pathlib.Path(
     63         arguments["<--interval-sound>"],
     64     ).expanduser().absolute()
     65     demarcation_sound_path = pathlib.Path(
     66         arguments["<--demarcation-sound>"],
     67     ).expanduser().absolute()
     68 
     69     session = Session(
     70         interval_time=interval_time,
     71         session_time=session_time,
     72         interval_sound_path=interval_sound_path,
     73         demarcation_sound_path=demarcation_sound_path,
     74     )
     75     session.meditate()
     76 
     77 
     78 if __name__ == "__main__":
     79     main()