Skip to content

frioux/teatime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

TeaTime: a CLI and half a webapp for tracking your teatimes!

INSTALLING DEPS

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 .

INSTALLATION

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

CONFIGURATION

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, and password 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 the server 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 in see_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.

ENVIRONMENT VARIABLES

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

USAGE

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_contact

Create a contact for use with the XMPP send functions used when setting the tea and marking the pot as ready

create_tea

Create a new tea for drinking

empty

Mark the pot as empty

event

Mark the pot with an arbitrary event

init

Generate a database

list_contacts

Print out a list of contacts

list_teas

Print out a list of teas

list_times

Print out a list of tea times

message

Send an arbitrary message to contacts

new_milk

Create a new milk for expiration tracking

ready

Mark a pot as ready

server

Start the built in server

set_tea

Set the current tea

timer

Run a timer for the current tea

toggle_contact

Enable/disable an XMPP contact

toggle_tea

Enalbe/disable a tea

undo

Undo the last tea you set

NEAT STUFF

Second Steeping

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"

Ghetto replication for SQLite

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 frew@t.mitsi.com:/home/frew/.teadb }

Apache and teadash

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!

SEE ALSO

http://github.com/gedarling/teadash for the other half

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages