Files
bike-part-tracker/get_all.sh
2024-10-13 23:21:42 +02:00

116 lines
3.3 KiB
Bash

#!/bin/bash
# python modul garmin export
# programmpfad /home/andre/.local/lib/python3.6/site-packages/garminexport
# dateien nicht auffindbar: /mnt/daten1tb/1_USER/andre/.tmp/.not_found
# dateien erledigt: /mnt/daten1tb/1_USER/andre/.tmp/.backed
# /usr/local/bin/garmin-backup
# /home/andre/.local/lib/python3.8/site-packages/garminexport/backup.py
#
# not_found_file = ".not_found"
# backed_file = ".backed"
#
# backed_up = os.listdir(backup_dir) + _not_found_activities(backup_dir) + _backed_activities(backup_dir)
# ...
# def _backed_activities(backup_dir):
# # consider all entries in <backup_dir>/.backed as backed up
# backed_activities = []
# _backed = os.path.join(backup_dir, backed_file)
# if os.path.isfile(_backed):
# with open(_backed, mode="r") as f:
# backed_activities = [line.strip() for line in f.readlines()]
# log.debug("%d already backed activities in %s", len(backed_activities), _backed)
# return backed_activities
### /usr/local/lib/python3.9/dist-packages/garminexport/garminclient.py
### https://github.com/petergardfjall/garminexport/pull/92/files
GRMNUSR=andregeissler@posteo.de
GRMNPWD=f7m8g36Ph4gDCy4
BCKDIR=/mnt/daten1tb/1_USER/andre/.tmp
ARCHDIR=/mnt/daten1tb/1_USER/andre/garmin/activities
DAYS=3
STD=`date '+%H'`
ALL=$1
holedateityp () {
typ=$1
echo
echo hole alle $typ
python3 /home/andre/.local/bin/garmin-backup -f $typ -E --backup-dir=$BCKDIR/ --password $GRMNPWD $GRMNUSR
}
echo
echo "\$BCKDIR : $BCKDIR"
echo "\$ARCHDIR : $ARCHDIR"
echo "\$DAYS : $DAYS"
echo
echo Löschen der Dateien der letzten $DAYS Tage
# hierdurch wird erzwungen diese Dateien neu zu holen, da Änderungen hier noch möglich sind
for d in `seq 0 $DAYS`
do
files=$(date +"%Y-%m-%d" -d "-$d day")
find $BCKDIR -name "$files*" -exec rm {} \;
done
echo
echo Dateien älter als $DAYS in .backed aufnehmen und löschen
cd $BCKDIR
d=$(expr $DAYS + 1)
files=$(date +"%Y-%m-%d" -d "-$d day")
ls -1R $files* >> .backed
rm $files*
echo
echo Download der Daten ins \$BCKDIR Verzeichnis
if [ "$ALL" == "fit" ] || [ "$ALL" == "all" ]; then holedateityp fit ; fi
if [ "$ALL" == "gpx" ] || [ "$ALL" == "all" ]; then holedateityp gpx ; fi
if [ "$ALL" == "tcx" ] || [ "$ALL" == "all" ]; then holedateityp tcx ; fi
if [ "$ALL" == "summary" ] || [ "$ALL" == "all" ]; then holedateityp json_summary ; fi
if [ "$ALL" == "details" ] || [ "$ALL" == "all" ]; then holedateityp json_details ; fi
echo
echo Dateien die jünger als \$DAYS Tage sind nach \$ARCHDIR kopieren
for I in `find $BCKDIR/* -mtime -$DAYS`
do
cp -a $I $ARCHDIR/
done
echo
echo Wechsel nach \$ARCHDIR
cd $ARCHDIR/
echo
echo Dateien der selben Aktivität zusammenfassen
for I in `ls -1 | grep -v zip | awk -F'_' '{print $2}' | awk -F'.' '{print $1}' | uniq`
do
DAT=`ls -1 *$I* | head -n1 | awk -F'+' '{print $1}'`
zip -u $DAT-$I.zip *$I*
done
rm *.tcx
rm *.gpx
rm *.fit
rm *.json
echo
echo Wenn Dateien mit Name JJJJ-MM - von 1930 bis 2070 - vorhanden sind, diese zippen
for I in `seq 1900 2070`
do
ls $I-??-* > /dev/null 2>&1
if [ "$?" == "0" ]
then
echo
echo Zip $I'-??-*' nach $I.zip
zip -u $I.zip $I-??-*
echo
echo Dateien älter als \$DAYS Tage aus \$ARCHDIR löschen
find $ARCHDIR/ -name "$I-??-*" -daystart -mtime +$DAYS | xargs rm -f
fi
done