Supression des fichiers temporaires en cas d'interruption
Détection de mot de passe incorrect
Divers petits fixes
-# crédit coopératif fetcher
+#
+# Crédit Coopératif account tools
+#
+# It fetch csv file and merge them to previous ones
+# It also generates a local file suitable for a feed reader
+#
# Depends on wget, iconv
set -e
LOGFILE=coop.log # unsued unless --log option is used
# Depends on wget, iconv
set -e
LOGFILE=coop.log # unsued unless --log option is used
-COOKIEJAR=cookiejar
-TMP=lastpage.html
+COOKIEJAR=cookiejar # cookies, deleted on exit
+TMP=lastpage.html # last html page, deleted on exit
function parsearg() {
_OPT="${1%=?*}"
function parsearg() {
_OPT="${1%=?*}"
function usage() {
#echo $'\n' $@ $'\n'
function usage() {
#echo $'\n' $@ $'\n'
- echo "Usage: coop.sh [options]"
+ echo "Usage: ccoop.sh [options]"
echo " -h|--help Display that help"
echo " -q|--quiet Don't display informationnal messages"
echo " -h|--help Display that help"
echo " -q|--quiet Don't display informationnal messages"
- echo " -l|--log Log requests to $LOGFILE"
+ echo " --log Log everything to $LOGFILE"
+ echo " --config Setup a config file"
#echo " --target=<filename> Set target filename. Defaults to $target_file"
#echo " --target=<filename> Set target filename. Defaults to $target_file"
- #echo "See man curcy-update(1) for documentation."
+ #echo "See man ccoop.sh(1) for documentation."
+ --config)
+ ismakeconfig=1
+ continue
+ ;;
-# That function prints messages, unless quiet is set
+# That function prints messages to stderr, unless quiet is set
# It logs into $LOGFILE if log is set, no matter whether quiet is set or not
function inform() {
if [ -n "$quiet" ]; then
if [ -n "$log" ]; then
# It logs into $LOGFILE if log is set, no matter whether quiet is set or not
function inform() {
if [ -n "$quiet" ]; then
if [ -n "$log" ]; then
+ echo $@ >> $LOGFILE >&2
fi
else # not quiet
if [ -n "$log" ]; then
fi
else # not quiet
if [ -n "$log" ]; then
- echo $@ | tee -a $LOGFILE
+ echo $@ | tee -a $LOGFILE >&2
+function makeconfig() {
+ read -p "Coopanet login: " COOPLOGIN
+ read -p "Coopanet password: " -s COOPPASSWORD
+ echo "# coopanet configuration">config
+ echo "COOPLOGIN=$COOPLOGIN">>config
+ echo "COOPPASSWORD=$COOPPASSWORD">>config
+ echo >&2
+ echo "config file writen" >&2
+}
+
- echo > $COOKIEJAR
- echo > $LOGFILE
+ echo> $COOKIEJAR
+ echo> $LOGFILE
inform "WGET login form"
fetch https://www.coopanet.com/banque/cpt/
inform "WGET login form"
fetch https://www.coopanet.com/banque/cpt/
inform "WGET cpt/connexion.do"
fetch https://www.coopanet.com/banque/cpt/cpt/connexion.do
inform "WGET cpt/connexion.do"
fetch https://www.coopanet.com/banque/cpt/cpt/connexion.do
+
+ if grep -q "Vous venez de quitter COOP@NET" $TMP; then
+ echo "Can't log in. Check password" >&2
+ fi
+
IFS=$'\n'
accountsId=(`grep numeroExterne $TMP | grep hidden | cut -d \" -f 6`)
accountsNames=(`grep "<td style=\"width:9%;\">" $TMP | cut -d ">" -f 2 | cut -d "<" -f 1`)
IFS=$'\n'
accountsId=(`grep numeroExterne $TMP | grep hidden | cut -d \" -f 6`)
accountsNames=(`grep "<td style=\"width:9%;\">" $TMP | cut -d ">" -f 2 | cut -d "<" -f 1`)
-umask 0077 # make sure the generated files are only readable by the user
+
+umask 0077 # make sure the generated files are only readable by the user
+
+if [[ -n $ismakeconfig ]]; then
+ makeconfig
+fi
+
+# Make sure our temporary files are deleted on error and on exit
+trap "rm -f $COOKIEJAR $TMP; exit" INT TERM EXIT
+
if [[ `ls -l config | cut -c 8-10` != "---" ]]; then
if [[ `ls -l config | cut -c 8-10` != "---" ]]; then
- echo "Security warning file should be chmod o-rwx"
+ echo "Security warning: config file should be chmod o-rwx" >&2
- inform "Warning, $LOG will contain sensitive information. You should delete it."
+ inform "Warning, $LOGFILE will contain sensitive information. You should delete it."
fetchall
updatehistory
atomize
fetchall
updatehistory
atomize