diff --git a/button1.py b/button1.py new file mode 100644 index 0000000..64c0c1a --- /dev/null +++ b/button1.py @@ -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')) diff --git a/diaper.py b/diaper.py new file mode 100644 index 0000000..7f4eabd --- /dev/null +++ b/diaper.py @@ -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" diff --git a/docast.py b/docast.py index e73bf3c..2b88aa8 100644 --- a/docast.py +++ b/docast.py @@ -1,12 +1,7 @@ +#!/usr/bin/python from __future__ import print_function import time import pychromecast -exroom=pychromecast.Chromecast('192.168.1.123') -lroom=pychromecast.Chromecast('192.168.1.107') home=pychromecast.Chromecast('192.168.1.103') -emc=exroom.media_controller -lmc=lroom.media_controller -hmc=home.media_controller +home.media_controller.play_media("http://192.168.1.14/doorbell.mp3",'audio/mpeg') home.wait() -time.sleep(5) -hmc.play_media('http://192.168.1.14/doorbell.mp3','audio/mpeg') diff --git a/feedings.py b/feedings.py new file mode 100644 index 0000000..935acca --- /dev/null +++ b/feedings.py @@ -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) diff --git a/hostlookup.py b/hostlookup.py new file mode 100644 index 0000000..d8dbd1d --- /dev/null +++ b/hostlookup.py @@ -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: diff --git a/logwatch.sh b/logwatch.sh index 5506c1c..09a884a 100644 --- a/logwatch.sh +++ b/logwatch.sh @@ -13,7 +13,7 @@ function procaplog(){ SENDALERT=$(checkdisconnects "$date" $mac) echo "starting mac check" echo "starting mac check" >> /var/log/logwatch.log - HOSTNAME=$(checkmac $mac) + HOSTNAME=$(/root/bin/hostlookup.py $mac "$date") if [ "$HOSTNAME" ]; then echo "__ $HOSTNAME __" echo "__ $HOSTNAME __" >> /var/log/logwatch.log @@ -25,7 +25,32 @@ function procaplog(){ else echo "Not alerting, Reconnection of $HOSTNAME" >> /var/log/logwatch.log 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) if [ $SENDALERT -eq 1 ]; then diff --git a/securitydvr.sh b/securitydvr.sh new file mode 100644 index 0000000..e5ff09c --- /dev/null +++ b/securitydvr.sh @@ -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 diff --git a/sleeptracker.py b/sleeptracker.py new file mode 100644 index 0000000..599a913 --- /dev/null +++ b/sleeptracker.py @@ -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'))