#!/bin/sh ############################################################################## # # # Copyright (C) 2010 by Michal Hrusecky # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################## TITLE="Auto" EMAIL="Michal@Hrusecky.net" PASS="supersecret" RECENT=10 export LANG="C" AUTH="`curl --silent https://www.google.com/accounts/ClientLogin -d Email=$EMAIL -d "Passwd=$PASS" -d source=cmdlineapp -d accountType=HOSTED -d service=writely | sed -n 's|Auth=||p'`" DATA="`curl --silent --header "Authorization: GoogleLogin auth=$AUTH" "https://docs.google.com/feeds/documents/private/full?title=$TITLE&title-exact=true"`" if [ -z "`echo "$DATA" | grep "1"`" ]; then echo "Too many results!!!" exit 1 fi DOCID="`echo "$DATA" | sed 's|.*docId=\([^&'"'"'"]\+\)[&'"'"'"].*|\1|' | head -n 1`" if [ -z "$DOCID" ]; then echo "Can't find docId!!!" exit 1 fi DATA="`curl --silent --header "Authorization: GoogleLogin auth=$AUTH" "https://docs.google.com/feeds/download/documents/Export?docId=$DOCID" | grep '^PET'`" [ -z "$RECENT" ] || DATA="`echo "$DATA" | tail -n "$RECENT"`" LITERS="`echo "$DATA" | sed -e 's|^\(PET:[0-9]*:[0-9]*:[0-9]\+.[0-9]\)l|\10l|' \ -e 's|^\(PET:[0-9]*:[0-9]*:[0-9]\+\)l|\1.00l|'`" LITERS="`echo "$LITERS" | sed 's|^PET:[0-9]*:[0-9]*:\([0-9]\+\).\([0-9][0-9]\)l|\1\2\ +|' | sed 's|+.*|+|' | head -n -1`" LITERS="`echo $LITERS` 0" LITERS="`expr $LITERS`" KM_S="`echo "$DATA" | sed -n 's|^PET:\([0-9]\+\):.*|\1|p' | head -n 1`" KM_E="`echo "$DATA" | sed -n 's|^PET:\([0-9]\+\):.*|\1|p' | tail -n 1`" KM="`expr $KM_E - $KM_S`" echo "Consumption: `expr \( $LITERS \* 10 \) / $KM | sed 's|\([0-9]\)$|.\1|'`l/100km"