moved moving of old records from bash to python
parent
ed136d3ea9
commit
28058f82d1
11
README.md
11
README.md
|
|
@ -1,10 +1,10 @@
|
||||||
#Weatherstation
|
#Weatherstation
|
||||||
##Overview
|
##Overview
|
||||||
Python, Bash, Tinkerforge
|
Python2, Bash, Tinkerforge
|
||||||
|
|
||||||
## Setup
|
## 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
|
2. `settings.py` anpassen
|
||||||
1. brickd-host und Port
|
1. brickd-host und Port
|
||||||
2. Verwendete Sensoren in *SENSORS* anpassen
|
2. Verwendete Sensoren in *SENSORS* anpassen
|
||||||
|
|
@ -15,5 +15,10 @@ Python, Bash, Tinkerforge
|
||||||
3. Tinkerforge-python-bindings installieren
|
3. Tinkerforge-python-bindings installieren
|
||||||
4. `all.py` starten, um Aufzeichnung zu starten
|
4. `all.py` starten, um Aufzeichnung zu starten
|
||||||
* Aufzeichnung des aktuellen Tages werden in `records` gespeichert
|
* 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
|
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
16
ftp.sh
|
|
@ -11,16 +11,14 @@ if [ ! -f $CONFIG ]; then
|
||||||
echo "configuration file not found, exiting! (see ftpconfig.sample.xml)"
|
echo "configuration file not found, exiting! (see ftpconfig.sample.xml)"
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
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
|
cd $DIR || exit 1
|
||||||
cp records/humi* ftp/
|
cp records/humi* $TMPDIR/
|
||||||
cp records/ambi* ftp/
|
cp records/ambi* $TMPDIR/
|
||||||
cp records/temp* ftp/
|
cp records/temp* $TMPDIR/
|
||||||
cp records/baro* ftp/
|
cp records/baro* $TMPDIR/
|
||||||
cd ftp
|
pushd $TMPDIR
|
||||||
|
|
||||||
|
|
||||||
if [ -z $SFTPPASS ]; then
|
if [ -z $SFTPPASS ]; then
|
||||||
#sftp-key-auth
|
#sftp-key-auth
|
||||||
sftp -oBatchMode=no -b - $SFTPUSER "$FTP_COMMAND"
|
sftp -oBatchMode=no -b - $SFTPUSER "$FTP_COMMAND"
|
||||||
|
|
@ -29,7 +27,7 @@ else
|
||||||
sshpass -p $SFTPPASS sftp -oBatchMode=no -b - $SFTPUSER "$FTP_COMMAND"
|
sshpass -p $SFTPPASS sftp -oBatchMode=no -b - $SFTPUSER "$FTP_COMMAND"
|
||||||
fi
|
fi
|
||||||
rm humi* ambi* temp* baro*
|
rm humi* ambi* temp* baro*
|
||||||
cd ..
|
popd
|
||||||
wget $URL -O logs/wget_recent -q
|
wget $URL -O logs/wget_recent -q
|
||||||
echo "ftpupload">>logs/ftp.log
|
echo "ftpupload">>logs/ftp.log
|
||||||
date>>logs/ftp.log
|
date>>logs/ftp.log
|
||||||
|
|
|
||||||
25
move.py
25
move.py
|
|
@ -4,17 +4,26 @@
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from timeFunctions import *
|
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):
|
if not os.path.exists(checkfile):
|
||||||
check=open(checkfile,'w')
|
open(checkfile,'w').close()
|
||||||
check.write('')
|
if not os.path.exists("arch"):
|
||||||
check.close()
|
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')
|
check=open(checkfile,'r')
|
||||||
temp=check.read()
|
temp=check.read()
|
||||||
|
|
@ -32,7 +41,7 @@ else:
|
||||||
log.flush()
|
log.flush()
|
||||||
if not os.path.exists("arch"):
|
if not os.path.exists("arch"):
|
||||||
os.mkdir("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.close()
|
||||||
check=open(checkfile,'w')
|
check=open(checkfile,'w')
|
||||||
check.write(str(time.time()))
|
check.write(str(time.time()))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue