Skip to content

Commit

Permalink
Check if the powerprice file already is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
KjellRanda committed Oct 25, 2024
1 parent 471adf7 commit 1dc68dd
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions powerprice.bash
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
#! /bin/bash
#
PWR_HOME="/data/python/prod"
PWR_HOME="/data/scripts"
PWR_PRICE="/data/powerprice"
PWR_TMP="/powerprice.new"
PWR_TSORT="powerprice.soeted"
PWR_OK="powerprice.list"
#
MV="/usr/bin/mv"
RM="/usr/bin/rm"
ECHO="/usr/bin/echo"
#
. /home/pi/.bashrc
cd $PWR_HOME
#
if [ -r $PWR_PRICE/$PWR_OK ]
then
NTOT=$(wc -l $PWR_PRICE/$PWR_OK | cut -d' ' -f1)
NTD=$(grep -c "^$(date --date=today '+%Y-%m-%d')" $PWR_PRICE/$PWR_OK)
NTM=$(grep -c "^$(date --date=tomorrow '+%Y-%m-%d')" $PWR_PRICE/$PWR_OK)
#
if [ $NTOT -eq 49 -a $NTD -eq 24 -a $NTM -eq 24 ]
then
$ECHO "Powerprice file $PWR_PRICE/$PWR_OK is already up to date"
exit
else
$ECHO "Powerprice file $PWR_PRICE/$PWR_OK is outdated. Creating new"
fi
else
$ECHO "Powerprice file $PWR_PRICE/$PWR_OK not found. Creating new"
fi
#
python powerprice.py NO5 > $PWR_PRICE/$PWR_TMP
#
if [ $? -eq 0 ]
then
$MV -f $PWR_PRICE/$PWR_TMP $PWR_PRICE/$PWR_OK
(head -n 1 $PWR_PRICE/$PWR_TMP && tail -n +2 $PWR_PRICE/$PWR_TMP | sort) > $PWR_PRICE/$PWR_TSORT
if [ $? -eq 0 ]
then
$MV -f $PWR_PRICE/$PWR_TSORT $PWR_PRICE/$PWR_OK
$RM -f $PWR_PRICE/$PWR_TMP
else
$RM -f $PWR_PRICE/$PWR_TMP $PWR_PRICE/$PWR_TSORT
fi
else
$RM -f $PWR_PRICE/$PWR_TMP
fi
#
#

0 comments on commit 1dc68dd

Please sign in to comment.