Created
December 9, 2011 14:33
-
-
Save emillon/1451758 to your computer and use it in GitHub Desktop.
Coffee counter
This file contains 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
#!/bin/bash | |
# comptage de café | |
# | |
# -> date de chaque + heure | |
# -> total de café + total euros | |
# | |
# | |
# utilisation : | |
# coffec -> ajout d'un café | |
# coffec reset -> remise à zero du log | |
# coffec help -> affiche un message d'aide | |
# quelques parametres d'utilisation | |
tarif=0.35 | |
fichier="$HOME/.coffee" | |
# creation du fichier s'il n'existe pas | |
:>> $fichier | |
if [ $# -eq 0 ] | |
then | |
date +'%d %B %Y, %T' >> $fichier | |
count=`wc -l < $fichier` | |
thunes=`echo "scale=2; $tarif * $count" | bc` | |
echo "Ardoise : $count café(s), $thunes €" | |
else | |
if [ $1 = "reset" ] | |
then | |
# vidage du fichier | |
:> $fichier | |
else | |
if [ $1 = "print" ] | |
then | |
cat $fichier | |
count=`wc -l < $fichier` | |
thunes=`echo "scale=2; $tarif * $count" | bc` | |
echo " * Total : $count café(s), $thunes €" | |
else | |
echo "Usages : " | |
echo " coffec" | |
echo " ajoute un café à l'ardoise, et affiche l'ardoise" | |
echo " coffec reset" | |
echo " efface l'ardoise" | |
echo " coffec print" | |
echo " affiche le detail de l'ardoise" | |
echo " coffec help" | |
echo " affiche ce message d'aide" | |
fi | |
fi | |
fi |
This file contains 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
#!/usr/bin/env python | |
import pynotify | |
import subprocess | |
import gtk | |
ICON_FILE = '/usr/share/gajim/data/emoticons/static/coffee.png' | |
def popup(msg): | |
w = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
l = gtk.Label(msg) | |
w.add(l) | |
l.show() | |
w.show() | |
def have_coffee(status_icon): | |
o = subprocess.check_output(['coffec']) | |
a = pynotify.Notification('Viva la fiesta', o) | |
a.show() | |
def ardoise(mi): | |
o = subprocess.check_output(['coffec', 'print']) | |
popup(o) | |
def reset(mi): | |
subprocess.check_call(['coffec', 'reset']) | |
def popup_menu(status_icon, button, activate_time): | |
m = gtk.Menu() | |
x = subprocess.check_output(['coffec', 'print']) | |
x = x.split("\n")[-2] | |
mi_total = gtk.MenuItem(x) | |
mi_ardoise = gtk.MenuItem('Ardoise') | |
mi_reset = gtk.MenuItem('RaZ') | |
mi_ardoise.connect('activate', ardoise) | |
mi_reset.connect('activate', reset) | |
m.append(mi_total) | |
m.append(mi_ardoise) | |
m.append(mi_reset) | |
mi_ardoise.show() | |
mi_reset.show() | |
mi_total.show() | |
m.popup(None, None, None, button, activate_time) | |
def main(): | |
pynotify.init("Coffec") | |
s = gtk.StatusIcon() | |
s.set_from_file(ICON_FILE) | |
s.set_tooltip("Coffec") | |
s.connect('activate', have_coffee) | |
s.connect('popup-menu', popup_menu) | |
gtk.main() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment