Lots of updates

Moved mac lookups to python and google sheet tab
added additional button actions
added tracking for sleep time on multiple buttons, feedings on multiple buttons, and dirty vs wet diapers.
This commit is contained in:
paradizelost 2017-07-13 09:10:05 -05:00
parent 640921722a
commit 58e8601d4c
8 changed files with 230 additions and 9 deletions

41
button1.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python
import gspread
import sys
import time
import datetime
from datetime import datetime
#toadd=sys.argv
#toadd.pop(0)
#mydate=sys.argv[0]
#buttonname=sys.argv[1]
from oauth2client.service_account import ServiceAccountCredentials
scope = "https://spreadsheets.google.com/feeds"
credentials = ServiceAccountCredentials.from_json_keyfile_name('/root/bin/credentials.json', scope)
gs = gspread.authorize(credentials)
gsheet = gs.open("testsheet")
wsheetname=sys.argv[1]
wsheet = gsheet.worksheet(wsheetname)
starttime= wsheet.acell('A2').value
endtime= wsheet.acell('B2').value
curtime=sys.argv[2]
print curtime
curyear = str(datetime.now().year)
curtime = datetime.strptime(curtime + ' ' + curyear,'%b %d %H:%M:%S %Y' )# 7/9/2017 17:28:46
#wsheet.insert_row([mydate,buttonname],index=2)
if starttime <> '':
if endtime <>'':
print 'both have values, starting new row'
wsheet.insert_row([curtime.strftime('%m/%d/%Y %H:%M:%S')],index=2)
else:
print 'start set, but end not, ending current set'
starttime = datetime.strptime(starttime, '%m/%d/%Y %H:%M:%S')
wsheet.update_acell('B2', curtime.strftime('%m/%d/%Y %H:%M:%S'))
timebetween = curtime - starttime
calcdiff = divmod(timebetween.total_seconds(),60)
minutes = calcdiff[0]
seconds = calcdiff[1]
minutes = "%g" % round(minutes,0)
wsheet.update_acell('C2', minutes + " Minutes" )
else:
print 'start time not set, starting set'
wsheet.update_acell('A2', curtime.strftime('%m/%d/%Y %H:%M:%S'))

26
diaper.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/python
import gspread
import sys
import time
import datetime
from datetime import datetime
#toadd=sys.argv
#toadd.pop(0)
#mydate=sys.argv[0]
#buttonname=sys.argv[1]
from oauth2client.service_account import ServiceAccountCredentials
scope = "https://spreadsheets.google.com/feeds"
credentials = ServiceAccountCredentials.from_json_keyfile_name('/root/bin/credentials.json', scope)
gs = gspread.authorize(credentials)
gsheet = gs.open("testsheet")
wsheet = gsheet.worksheet("DiaperChange")
curtime=sys.argv[1]
diapertype=sys.argv[2]
curyear = str(datetime.now().year)
curtime = datetime.strptime(curtime + ' ' + curyear,'%b %d %H:%M:%S %Y' )# 7/9/2017 17:28:46
if diapertype == 'wet':
wsheet.insert_row([curtime.strftime('%m/%d/%Y %H:%M:%S'),'WET'],index=2)
print "WET DIAPER"
else:
wsheet.insert_row([curtime.strftime('%m/%d/%Y %H:%M:%S'),'SOILED'],index=2)
print "SOILED DIAPER"

View File

@ -1,12 +1,7 @@
#!/usr/bin/python
from __future__ import print_function from __future__ import print_function
import time import time
import pychromecast import pychromecast
exroom=pychromecast.Chromecast('192.168.1.123')
lroom=pychromecast.Chromecast('192.168.1.107')
home=pychromecast.Chromecast('192.168.1.103') home=pychromecast.Chromecast('192.168.1.103')
emc=exroom.media_controller home.media_controller.play_media("http://192.168.1.14/doorbell.mp3",'audio/mpeg')
lmc=lroom.media_controller
hmc=home.media_controller
home.wait() home.wait()
time.sleep(5)
hmc.play_media('http://192.168.1.14/doorbell.mp3','audio/mpeg')

20
feedings.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/python
import gspread
import sys
import time
import datetime
from datetime import datetime
#toadd=sys.argv
#toadd.pop(0)
#mydate=sys.argv[0]
#buttonname=sys.argv[1]
from oauth2client.service_account import ServiceAccountCredentials
scope = "https://spreadsheets.google.com/feeds"
credentials = ServiceAccountCredentials.from_json_keyfile_name('/root/bin/credentials.json', scope)
gs = gspread.authorize(credentials)
gsheet = gs.open("testsheet")
wsheet = gsheet.worksheet("Feeding")
curtime=sys.argv[1]
curyear = str(datetime.now().year)
curtime = datetime.strptime(curtime + ' ' + curyear,'%b %d %H:%M:%S %Y' )# 7/9/2017 17:28:46
wsheet.insert_row([curtime.strftime('%m/%d/%Y %H:%M:%S')],index=2)

34
hostlookup.py Normal file
View File

@ -0,0 +1,34 @@
#!/usr/bin/python
import gspread
import sys
import time
import datetime
from datetime import datetime
#toadd=sys.argv
#toadd.pop(0)
#mydate=sys.argv[0]
#buttonname=sys.argv[1]
from oauth2client.service_account import ServiceAccountCredentials
scope = "https://spreadsheets.google.com/feeds"
credentials = ServiceAccountCredentials.from_json_keyfile_name('/root/bin/credentials.json', scope)
gs = gspread.authorize(credentials)
gsheet = gs.open("testsheet")
wsheet = gsheet.worksheet("Hosts")
#starttime= wsheet.acell('A2').value
#endtime= wsheet.acell('B2').value
macaddr=sys.argv[1]
curtime=sys.argv[2]
curyear = str(datetime.now().year)
curtime = datetime.strptime(curtime + ' ' + curyear,'%b %d %H:%M:%S %Y' )# 7/9/2017 17:28:46
cell = wsheet.find(macaddr)
if cell is not None:
hostname = wsheet.cell(cell.row,cell.col+1)
lastseencolumn = cell.col + 2
wsheet.update_cell(cell.row,lastseencolumn,curtime)
print hostname.value
else:
wsheet.insert_row([macaddr,'UNKOWN_HOST',curtime],index=2)
print "UNKNOWN_HOST"
#if starttime <> '':
# wsheet.appendrow();
#else:

View File

@ -13,7 +13,7 @@ function procaplog(){
SENDALERT=$(checkdisconnects "$date" $mac) SENDALERT=$(checkdisconnects "$date" $mac)
echo "starting mac check" echo "starting mac check"
echo "starting mac check" >> /var/log/logwatch.log echo "starting mac check" >> /var/log/logwatch.log
HOSTNAME=$(checkmac $mac) HOSTNAME=$(/root/bin/hostlookup.py $mac "$date")
if [ "$HOSTNAME" ]; then if [ "$HOSTNAME" ]; then
echo "__ $HOSTNAME __" echo "__ $HOSTNAME __"
echo "__ $HOSTNAME __" >> /var/log/logwatch.log echo "__ $HOSTNAME __" >> /var/log/logwatch.log
@ -25,7 +25,32 @@ function procaplog(){
else else
echo "Not alerting, Reconnection of $HOSTNAME" >> /var/log/logwatch.log echo "Not alerting, Reconnection of $HOSTNAME" >> /var/log/logwatch.log
fi fi
python /root/bin/docast.py python /root/bin/button1.py "$HOSTNAME" "$date"
#castnow --address 192.168.1.103 http://192.168.1.14/doorbell.mp3 --exit
;;
HEFTY)
/root/bin/sleeptracker.py "$date"
;;
COLGATE)
/root/bin/sleeptracker.py "$date"
;;
AMAZON_BASICS_BATTERIES)
/root/bin/sleeptracker.py "$date"
;;
CASCADE)
/root/bin/sleeptracker.py "$date"
;;
Charmin_1)
/root/bin/feedings.py "$date"
;;
CHARMIN_2)
/root/bin/feedings.py "$date"
;;
DIRTY_DIAPER)
/root/bin/diaper.py "$date" soiled
;;
WET_DIAPER)
/root/bin/diaper.py "$date" wet
;; ;;
DAN_PIXEL) DAN_PIXEL)
if [ $SENDALERT -eq 1 ]; then if [ $SENDALERT -eq 1 ]; then

41
securitydvr.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
PVR1_URL="http://user:user123@192.168.2.100/tmpfs/snap.jpg"
PVR1_NAME="GarageCam"
PVR2_URL="http://192.168.2.102:8080/photo.jpg"
PVR2_NAME="RackCam"
STORAGE_PATH=~/pvr
function createpaths(){
PVRNAME=$1
YEAR="$(date +"%Y")"
MONTH="$(date +"%m")"
DAY="$(date +"%d")"
if [ ! -d "$STORAGE_PATH/$PVRNAME/$YEAR/$MONTH/$DAY" ]; then
mkdir "$STORAGE_PATH/$PVRNAME/$YEAR/$MONTH/$DAY" -p
fi
echo "$STORAGE_PATH/$PVRNAME/$YEAR/$MONTH/$DAY"
}
function getimage(){
#set -x
URL=$1
PVRPATH=$2
STAMP="$(date +"%H-%M-%S")"
wget $URL -O "$PVRPATH/$STAMP.jpg" --quiet -U "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.17 (KHTML, like Gecko) Ubuntu/11.04 Chromium/11.0.654.0 Chrome/11.0.654.0 Safari/534.17"
}
function processdvrs(){
PVR1PATH=$(createpaths $PVR1_NAME)
#PVR2PATH=$(createpaths $PVR2_NAME)
getimage $PVR1_URL $PVR1PATH
#getimage $PVR2_URL $PVR2PATH
}
TIMER=0
while true; do
TIMER=$(($TIMER + 1))
processdvrs
if [ "$TIMER" -gt "1000" ]; then
rclone move ~/pvr secret:pvr &
TIMER=0
fi
done

39
sleeptracker.py Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/python
import gspread
import sys
import time
import datetime
from datetime import datetime
#toadd=sys.argv
#toadd.pop(0)
#mydate=sys.argv[0]
#buttonname=sys.argv[1]
from oauth2client.service_account import ServiceAccountCredentials
scope = "https://spreadsheets.google.com/feeds"
credentials = ServiceAccountCredentials.from_json_keyfile_name('/root/bin/credentials.json', scope)
gs = gspread.authorize(credentials)
gsheet = gs.open("testsheet")
wsheet = gsheet.worksheet('BabySleep')
starttime= wsheet.acell('A2').value
endtime= wsheet.acell('B2').value
curtime=sys.argv[1]
print curtime
curyear = str(datetime.now().year)
curtime = datetime.strptime(curtime + ' ' + curyear,'%b %d %H:%M:%S %Y' )# 7/9/2017 17:28:46
if starttime <> '':
if endtime <>'':
print 'both have values, starting new row'
wsheet.insert_row([curtime.strftime('%m/%d/%Y %H:%M:%S')],index=2)
else:
print 'start set, but end not, ending current set'
starttime = datetime.strptime(starttime, '%m/%d/%Y %H:%M:%S')
wsheet.update_acell('B2', curtime.strftime('%m/%d/%Y %H:%M:%S'))
timebetween = curtime - starttime
calcdiff = divmod(timebetween.total_seconds(),60)
minutes = calcdiff[0]
seconds = calcdiff[1]
minutes = "%g" % round(minutes,0)
wsheet.update_acell('C2', minutes + " Minutes" )
else:
print 'start time not set, starting set'
wsheet.update_acell('A2', curtime.strftime('%m/%d/%Y %H:%M:%S'))