step two: rest of the fucking owl
This commit is contained in:
parent
cc2e604cf4
commit
a4b09eef06
2
.gitignore
vendored
2
.gitignore
vendored
@ -168,3 +168,5 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# project-specific
|
||||||
|
audio/
|
||||||
|
14
README.md
14
README.md
@ -1,3 +1,15 @@
|
|||||||
# dinnerbell
|
# dinnerbell
|
||||||
|
|
||||||
Teaching my cat to tell time with Pavlovian conditioning
|
Teaching my cat to tell time with Pavlovian conditioning
|
||||||
|
|
||||||
|
# Set-up
|
||||||
|
|
||||||
|
Install dependencies:
|
||||||
|
|
||||||
|
```
|
||||||
|
echo
|
||||||
|
```
|
||||||
|
|
||||||
|
and run:
|
||||||
|
|
||||||
|
python dinnerbell.py
|
||||||
|
46
dinnerbell.py
Executable file
46
dinnerbell.py
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
import random
|
||||||
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
DEFAULT_WATCH_DIRECTORY = "audio"
|
||||||
|
|
||||||
|
def play_audio(file_path):
|
||||||
|
try:
|
||||||
|
subprocess.run(["ffplay", "-nodisp", "-autoexit", "-loglevel", "quiet", file_path])
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error playing {file_path}: {e}")
|
||||||
|
|
||||||
|
def play_audio_for_current_time(watch_dir):
|
||||||
|
current_time = datetime.datetime.now().strftime('%H:%M')
|
||||||
|
file_path = os.path.join(watch_dir, f"{current_time}.wav")
|
||||||
|
folder_path = os.path.join(watch_dir, current_time)
|
||||||
|
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
print(f"Playing '{file_path}'")
|
||||||
|
play_audio(file_path)
|
||||||
|
elif os.path.isdir(folder_path):
|
||||||
|
wav_files = [f for f in os.listdir(folder_path) if f.lower().endswith('.wav')]
|
||||||
|
if wav_files:
|
||||||
|
selected_file = os.path.join(folder_path, random.choice(wav_files))
|
||||||
|
print(f"Playing '{selected_file}'")
|
||||||
|
play_audio(selected_file)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--directory', default=DEFAULT_WATCH_DIRECTORY, help='Folder to read audio files from')
|
||||||
|
parser.add_argument('--daemon', action='store_true', help='Run in daemon mode')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
play_audio_for_current_time(args.directory)
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
seconds_until_next_minute = 60 - now.second
|
||||||
|
if not args.daemon:
|
||||||
|
break
|
||||||
|
print(f"Using audio from path '{args.directory}'")
|
||||||
|
time.sleep(seconds_until_next_minute)
|
15
dinnerbell.service
Normal file
15
dinnerbell.service
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Dinnerbell Python script
|
||||||
|
After=network.target sound.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/dinnerbell --daemon --directory=${AUDIO_DIR}
|
||||||
|
Environment=AUDIO_DIR=/etc/dinnerbell/audio
|
||||||
|
Restart=on-failure
|
||||||
|
User=nobody
|
||||||
|
Group=nogroup
|
||||||
|
WorkingDirectory=/opt/dinnerbell/
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
13
install.sh
Executable file
13
install.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
|
|
||||||
|
mkdir -p /opt/dinnerbell/ && \
|
||||||
|
/usr/bin/cp "$SCRIPT_DIR"/dinnerbell.py /opt/dinnerbell/dinnerbell.py && \
|
||||||
|
chmod +x /opt/dinnerbell/dinnerbell.py && \
|
||||||
|
ln -sf /opt/dinnerbell/dinnerbell.py /usr/bin/dinnerbell && \
|
||||||
|
mkdir -p /etc/dinnerbell/audio/ && \
|
||||||
|
chmod 777 /etc/dinnerbell/audio/ && \
|
||||||
|
/usr/bin/cp "$SCRIPT_DIR"/dinnerbell.service /etc/systemd/system/dinnerbell.service && \
|
||||||
|
systemctl daemon-reload && \
|
||||||
|
systemctl restart playclock.service
|
Loading…
x
Reference in New Issue
Block a user