mezamashi - めざまし

A Terminal Alarm Clock written in Python

No, this is not the “learning japanese - 2nd semester” post, despite one could think that at first glance. But that will be coming soon, too. ;)

This is the result of some of the few times where I had time to code a little during the last semester, and as some friends showed interest, I’ve decided to publish what started as my apprentice piece with scriptine.

Instead of repeating what I wrote in my readme, let me just quote it:

Regular alarm clocks have the disadvantage of not turning off your computer when it’s time to sleep, they just beep when it’s time to get up.

To prevent you from finishing “just this little thing” and getting to bed too late, you can set up mezamashi to shut down your computer at a specific time beforehand, e.g. in 2 hours, and to wake you up with a nice song in your media player or anything else you can steer from the command line.

But the crucial point is that it turns on your computer when it’s time to get up and lets you know that - so it uses the force that keeps you at your computer and out of bed at bedtime to get you out of bed (and, unfortunately, at the computer again) when it’s time to get up.

The only thing left for you is to get out of the house in time, but at least your early-morning sleapyness shouldn’t make you stay in bed anymore. ;)

The code can be found on github and is licensed under GPLv3.

Let me show you some example calls:

# set a wakeup alarm to 8 o'clock
>./mezamashi.py set 8:00
# show the current alarm
>./mezamashi.py show
# disable the current alarm
>./mezamashi.py unset
# set a wakeup alarm in 7 hours and a half
>./mezamashi.py set 7h30
# go to sleep in 20 minutes. you need to use this command to suspend to run your alarm_shcommand at next startup.
>./mezamashi.py sleep 0h20
# there's an alias if you want to suspend immediatly
>./mezamashi.py sleep now

Most of the work was done with scriptine, it’s a nice library providing a simple interface for all the shell scripting stuff like exececuting commands and doing file system operations. On top of that, it has a really nice way of defining commands and options in your shellscript, which saves you from repeating more or less the same OptionParser stuff for every shell script you write.

Scriptine really is a great help for shell scripting in python, and from now on, whenever I’m writing a shell script that consists of more than just some rows of commands to be executed, I think I’ll save myself from writing bash if statements (I think I’ve never managed to write one without copying the syntax from somewhere and slightly modifying it) by converting everything to Python + scriptine. :)

The Name

mezamashi is, as you might have guessed, the japanese word for alarm clock. ‘wecker’, the german word, was already taken, so I chose mezamashi to make me remember a vocable without doing anything for it. ;)

Remarks? Additions? Corrections? For anything you want to tell me about this blog post, feel free to send me an email[*].
Despite having no comments section (isn't that easy with a static site generator and without relying on a proprietary 3rd party service), I greatly appreciate direct feedback. 😉 In case of additions, I'll mention the name from the mail if you don't object.

[*]: Mails from small independent mailservers are my mailserver's favourite! ❤
If you don't want to keep one on your own, you can pay various admins about 1€ per month to do so for you, e.g. at posteo, mailbox.org, jit-creatives, or at most webhosting providers like netcup or 1&1 in case you want to have your own domain name on top.