### BEGIN INIT INFO
# Provides: wecker
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start wecker at boot time
# Description: Enable service provided by wecker.
### END INIT INFO
#!/bin/sh
PLAYER="/usr/bin/mpg123"
AMIXER="/usr/bin/amixer"
PLAYER_OPTIONS="--random --index --control --list"
# put outside of encrypted home dirs etc. because you want it to start before logging in
PLAYLIST="/var/wecker-muzaq/wecker.playlist"
SLEEPTIME="5"
# don't run after this hour
TIME_THRESHOLD="22"
SET_VOL_MASTER="$AMIXER set 'Master',0 75% > /dev/null"
SET_VOL_HEADPHONEJACK="$AMIXER set 'Headphone',0 100% > /dev/null"
SET_VOL_SPEAKERS="$AMIXER set 'Master',0 100% > /dev/null"
SET_VOLUME="$SET_VOL_MASTER; $SET_VOL_HEADPHONEJACK; $SET_VOL_SPEAKERS"
UNMUTE_MASTER="$AMIXER set 'Master',0 unmute > /dev/null"
UNMUTE_HEADPHONEJACK="$AMIXER set 'Headphone',0 unmute > /dev/null"
UNMUTE_SPEAKERS="$AMIXER set 'Speaker',0 unmute > /dev/null"
UNMUTE="$UNMUTE_MASTER; $UNMUTE_HEADPHONEJACK; $UNMUTE_SPEAKERS"
LOGFILE="/var/log/messages"
KILL="/bin/kill -9"
# attached keyboard
SNOOZE_DEV="/dev/input/event3"
# use script from http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/
# to determine device no.
# uncomment echo "EVENT=$EVENT" below to see what the different codes are
SNOOZE_KEY="0039" # spacebar
STOP_KEY="000e" # backspace
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root!" 1>&2
exit 1
fi
# got this sub from somewhere; what exactly does this do and how?
# can't use keyword 'function' b/c it's not recognised by /bin/sh
getkey ()
{
KEYPRESS=$(dd if=$SNOOZE_DEV bs=16 count=1 2>/dev/null | od -x | grep -v 0000020)
#echo $KEYPRESS
echo $KEYPRESS > /tmp/event.tmp
EVENT=$(cut -b 39-42 /tmp/event.tmp)
rm /tmp/event.tmp
}
case "$1" in
start)
TIME=$(date +%k)
if [ $TIME -lt $TIME_THRESHOLD ]; then
$UNMUTE
$SET_VOLUME
$PLAYER $PLAYER_OPTIONS $PLAYLIST &
if [ $? -eq 0 ]; then
echo "$(date) started wecker" >> $LOGFILE
fi
while true; do
getkey
#echo "EVENT=$EVENT"
case $EVENT in
$SNOOZE_KEY)
$KILL $(pidof $PLAYER)
echo "$(date) snoozing wecker for $SLEEPTIME" >> $LOGFILE
sleep $SLEEPTIME
$PLAYER $PLAYER_OPTIONS $PLAYLIST &
if [ $? -eq 0 ]; then
echo "$(date) restarted wecker after having snoozed $SLEEPTIME" >> $LOGFILE
fi
;;
$STOP_KEY)
$KILL $(pidof $PLAYER)
if [ $? -eq 0 ]; then
echo "$(date) stopped wecker" >> $LOGFILE
fi
exit 1
;;
esac
done
fi
;;
stop)
echo -n "Stopping wecker init script"
$KILL $(pidof $PLAYER)
if [ $? -eq 0 ]; then
echo "stopped wecker" >> $LOGFILE
fi
;;
*)
echo "Usage: /etc/init.d/wecker {start|stop}"
exit 1
;;
esac
exit 0
20110728
wecker / alarm clock
20110716
how much money do i spend on food (aka in supermarkets)?
prerequisites: csv from your bank which holds all relevant transaction data (you will have to pay electronically to get your transactions recorded, of course)
modify if necessary: supermarket identifiers (@markets)
modify if necessary: supermarket identifiers (@markets)
#!/usr/bin/perl
## extracts and displays those amounts from your bank's transactions csv file
## which have gone to supermarkets and calculates a total sum (for some timeperiod, for example)
## expects beneficiary column before amount column
## Text::CSV::Simple expects commas for separators, you may have to tweak your csv format; otherwise you'll see a lot of "Failed on" output
## usage:
## perl $0 [csvfile] [beneficiary_col] [amount_col]
## e.g.
## perl supermarkets.pl umsatz.csv 6 9
use strict;
use warnings;
#use Data::Dumper; # for debugging hashrefs
use Text::CSV::Simple;
# install with: perl -MCPAN -e "install Text::CSV::Simple"
my @markets = qw(KAISERS E-REICHELT REWE LIDL);
my $markets = join('|', @markets); # for regex matching
my $csvfile = shift;
my $beneficiary_col = shift; # column no. where to expect (among others) the markets' names
my $amount_col = shift; # column no. where to expect the amount
my ($amount_total, $match) = (0) x 2;
my $parser = Text::CSV::Simple->new;
# Text::CSV::Simple's column count starts with 0 so we have to correct the user input field numbers
$parser->want_fields($beneficiary_col-1, $amount_col-1);
# caution: field naming sorts somewhat(?) alphabetically
$parser->field_map(qw/1 2/);
# gets array of hashes
my @lines = $parser->read_file($csvfile);
# debugging hashrefs (where's all the expected data?)
#print Dumper(\@lines);
# print csv-style headers
print "Supermarkt;Betrag;Summe\n";
foreach my $line (@lines) {
foreach my $column (keys %{$line}) {
if (${$line}{$column} =~ /$markets/) {
print ${$line}{$column};
$match = 1; # found a market string in this field
}
# we have found a market,
# so now we're interested in the next field
elsif ($match == 1) {
print ";${$line}{$column}"; # amount
${$line}{$column} =~ s/,/\./; # swap ',' with '.' in amount so we can calc
$amount_total += ${$line}{$column};
print ";$amount_total\n";
$match = 0; # reset
}
}
}
Abonnieren
Kommentare (Atom)