TeaTime: a CLI and half a webapp for tracking your teatimes!
This program uses Perl and a number of Perl modules. The easiest way to install the modules is: (skip this first bit if you perl it up regularly)
curl -L http://cpanmin.us | perl - --sudo App::cpanminus
cpanm --installdeps .
Next, what I intially did was added /home/frew/code/teatime to my path, but an alias is probably more sensible:
alias t=/home/frew/code/teatime/bin/tea
If you want to use all of the features of teatime you need to set up a config file like the one included in this repo in your home directory. The following is what the various bits of the config mean:
db
-
the connect string for your database. You probably just want to use SQLite. In which case
dbi:SQLite:dbname=$file;sqlite_unicode=1
is sufficient. Note that if you do want to use some other database for performance or something that is supported. xmpp
-
this allows will instant message people when the tea is chosen and marked as ready.
server
is the xmpp server,jid
is username, andpassword
is the password. servers
-
these are urls used in the xmpp messages
web_server
-
listen_on
: the ip address to listen on this is only useful if you want to use theserver
command to run a perl based server locally. The server is performant enough for serving up to the world, but once you do a full on deploy you probably want to use an init script or Ubic or something like that.base_url
: this gets prepended to all the links insee_also
. The main use is for if you've set up apache to proxy to this server or something and you want the links to work.
TXMPP
-
Set this to false if you want to disable sending messages
TDB
-
Set this to false if you want to disable writing to the database
TTWEET
-
Set this to false if you want to disable twitter message
For the most part the app level documentation (accessed by just running the program) is good enough, but I will give an overview of all the features here.
A typical day in the use of this tool will go as follows:
# set the tea to hazelbank (send message to contacts in case they hate the tea)
t set_tea hazel
# start the timer after cleaning the pot etc
t timer
# mark the pot as ready (send message to tell people tea is ready)
t ready
# mark pot as empty (for statistics based on how quickly people drink tea)
t empty
Create a contact for use with the XMPP send functions used when setting the tea and marking the pot as ready
Create a new tea for drinking
Mark the pot as empty
Mark the pot with an arbitrary event
Generate a database
Print out a list of contacts
Print out a list of teas
Print out a list of tea times
Send an arbitrary message to contacts
Create a new milk for expiration tracking
Mark a pot as ready
Start the built in server
Set the current tea
Run a timer for the current tea
Enable/disable an XMPP contact
Enalbe/disable a tea
Undo the last tea you set
I haven't added second (or more) steep code to the codebase, but thanks to a few vanilla features and unix we can do it quite handily:
t message "Second Steeping $(t list_times | tail -n1 | cut -b13-)"
t event "Starting 2nd Steep"
TDB=0 TXMPP=0 t timer 360
t event "Stopped 2nd Steep"
t message "Second Steep of $(t list_times | tail -n1 | cut -b13-) ready"
I still can't quite bring myself to deploy this on a real database. SQLite is just so handy! That means that I either need to run the CLI of teatime on a remote server or I need to syncronize SQLite over. I wrote a handy shell function to syncronize the files over as needed. If you do this make sure to run ssh-copy-id $remote_host
so that you won't have to type in a password all the time.
t() { tea $@ && [[ ( $1 == create_tea ) || \
( $1 == empty ) || \
( $1 == ready ) || \
( $1 == set_tea ) || \
( $1 == timer ) || \
( $1 == event ) || \
( $1 == undo ) \
]] && \
scp ~/.teadb [email protected]:/home/frew/.teadb }
My coworker made teadash, which is a handy at-a-glance tool for the tea information. Setting it up with Apache is great if you want to set up an external site like we did.
First, configure teatime
and teadash
. They can share a configuration file. The following is the config file for our web server:
{
"db":"dbi:SQLite:dbname=/home/frew/.teadb;sqlite_unicode=1",
"web_server":{
"listen_on":"localhost",
"base_url":"http://t.mitsi.com/api"
},
"dash":{
"spec_file":"teatime.json",
"api_base_url":"http://localhost:5001/",
"webroot":"/home/frew/code/teadash/static"
}
}
Note that I'm running the servers under my user. This works fine as Apache will be proxying to them. The main things to take note of are the web_server
, and dash
configs. webserver.base_url
is so that the urls will work as links if people use JSONView
. dash.api_base_url
is whatever url the api web server will be running on, and dash.webroot
is the full path to the static files in dash.
As for the Apache config, all I did was the following:
<VirtualHost *:80>
ExpiresActive On
ProxyRequests Off
<Proxy balancer://dash>
BalancerMember http://127.0.0.1:5000
</Proxy>
<Proxy balancer://time>
BalancerMember http://127.0.0.1:5001
</Proxy>
ProxyPass /api/ balancer://time/
ProxyPass / balancer://dash/
DocumentRoot "/home/frew/code/teadash/static"
<Location /static>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetHandler default-handler
</Location>
</VirtualHost>
Works great!
http://github.com/gedarling/teadash for the other half