moved moving of old records from bash to python

master
agp8x 2015-08-24 15:45:27 +02:00
parent ed136d3ea9
commit 28058f82d1
4 changed files with 32 additions and 35 deletions

View File

@ -1,10 +1,10 @@
#Weatherstation
##Overview
Python, Bash, Tinkerforge
Python2, Bash, Tinkerforge
## Setup
1. Pfade, Urls und Benutzer in `ftp.sh` anpassen
1. Pfade, Urls und Benutzer in `ftpconfig.xml` anpassen (Vorlage: ftpconfig.sample.xml)
2. `settings.py` anpassen
1. brickd-host und Port
2. Verwendete Sensoren in *SENSORS* anpassen
@ -15,5 +15,10 @@ Python, Bash, Tinkerforge
3. Tinkerforge-python-bindings installieren
4. `all.py` starten, um Aufzeichnung zu starten
* Aufzeichnung des aktuellen Tages werden in `records` gespeichert
* Nach dem Upload und dem Tagesende werden die Aufzeichnungen nach `arch` verschoben
* (ftp.sh bzw move.py) Nach dem Upload und dem Tagesende werden die Aufzeichnungen nach `arch` verschoben
5. Cronjob für Upload mit ftp.sh einrichten
# TODOS
* Logging auf loghandler umstellen [https://docs.python.org/2/library/logging.html#handler-objects](https://docs.python.org/2/library/logging.html#handler-objects)
* auf python3 umstellen
* settings aus python auslagern

16
ftp.sh
View File

@ -11,16 +11,14 @@ if [ ! -f $CONFIG ]; then
echo "configuration file not found, exiting! (see ftpconfig.sample.xml)"
exit 1;
fi
read DIR SFTPUSER URL SFTPPASS < <(xmlstarlet sel -t -v "//dir" -o $'\t' -v "//sftpuser" -o $'\t' -v "//url" -o $'\t' -v "//sftppass" $CONFIG)
read DIR SFTPUSER URL TMPDIR SFTPPASS < <(xmlstarlet sel -t -v "//dir" -o $'\t' -v "//sftpuser" -o $'\t' -v "//url" -o $'\t' -v "//tmp-dir" -o $'\t' -v "//sftppass" $CONFIG)
cd $DIR || exit 1
cp records/humi* ftp/
cp records/ambi* ftp/
cp records/temp* ftp/
cp records/baro* ftp/
cd ftp
cp records/humi* $TMPDIR/
cp records/ambi* $TMPDIR/
cp records/temp* $TMPDIR/
cp records/baro* $TMPDIR/
pushd $TMPDIR
if [ -z $SFTPPASS ]; then
#sftp-key-auth
sftp -oBatchMode=no -b - $SFTPUSER "$FTP_COMMAND"
@ -29,7 +27,7 @@ else
sshpass -p $SFTPPASS sftp -oBatchMode=no -b - $SFTPUSER "$FTP_COMMAND"
fi
rm humi* ambi* temp* baro*
cd ..
popd
wget $URL -O logs/wget_recent -q
echo "ftpupload">>logs/ftp.log
date>>logs/ftp.log

25
move.py
View File

@ -4,17 +4,26 @@
import time
import os
from timeFunctions import *
from settings import locks, logs
from shutil import move
# TODO: path from settings
checkfile='locks/records_moved'
checkfile=locks+'/records_moved'
if not os.path.exists(logs+"/move.log"):
open(logs+"/move.log", 'w').close()
if not os.path.exists(checkfile):
check=open(checkfile,'w')
check.write('')
check.close()
open(checkfile,'w').close()
if not os.path.exists("arch"):
os.mkdir("arch", 0000755)
log=open("logs/move.log",'a')
def mycopy(keep):
names = os.listdir("records")
for name in names:
if keep in name:
continue
move(os.path.join("records", name), "arch")
log=open(logs+"/move.log",'a')
check=open(checkfile,'r')
temp=check.read()
@ -32,7 +41,7 @@ else:
log.flush()
if not os.path.exists("arch"):
os.mkdir("arch")
os.system("./move.sh "+preptime()) # TODO: replace me with: https://docs.python.org/2/library/shutil.html#module-shutil
mycopy(preptime())
check.close()
check=open(checkfile,'w')
check.write(str(time.time()))

15
move.sh
View File

@ -1,15 +0,0 @@
#!/bin/bash
cd records
#echo $1
for f in {temp,humi,ambi,baro}*
do
#echo $f
day=`echo $f|cut -d"_" -f2`
if [ "$day" == "$1" ]; then
echo "$f today"
else
echo "$f old, -->move"
mv $f ../arch
fi
done
cd ..