Last active
June 25, 2024 16:39
-
-
Save fguillen/cb7d5e6ee9be5a306e0e71f0284496e6 to your computer and use it in GitHub Desktop.
Announce the beer time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple but necessary script (for Mac) to announce when the beer time is comming | |
# You can configure your crontab like this | |
# 0 17 * * 5 ruby $HOME/scripts/beer_time.rb >> /var/log/beer_time.log 2>&1 | |
beer_hour = ARGV[0] || 18 | |
def say(message) | |
`afplay /System/Library/Sounds/Hero.aiff` | |
`afplay /System/Library/Sounds/Hero.aiff` | |
`say "#{message}"` | |
end | |
while(true) | |
now = Time.new | |
beer_time = Time.local(now.year, now.month, now.day, beer_hour, 0) | |
seconds_to_beer_time = beer_time - now | |
if seconds_to_beer_time <= 0 | |
say("We are officially now at beer time") | |
exit 0 | |
else | |
say("We are at #{(seconds_to_beer_time / 60.to_f).round(1)} minutes to beer time") | |
end | |
seconds_to_sleep = rand(seconds_to_beer_time / 2) + 10 # minimum 10 seconds | |
seconds_to_sleep = seconds_to_beer_time if seconds_to_sleep > seconds_to_beer_time | |
puts "Next anouncement at #{Time.now + seconds_to_sleep}" | |
sleep(seconds_to_sleep) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some suggestions for modificaitons:
ruby beer_time.rb --test
=> 📢 'It is 40 minutes to beer time'curl -s http://x.com/x.mp3 > /tmp/x.mp3 && afplay /tmp/x.mp3
Will this redownload the file if its already there? If not we get free caching ;)