From 668081a828c64916cff6edf4fdf27399576ff608 Mon Sep 17 00:00:00 2001 From: Level2 Pidor Date: Thu, 28 Jan 2016 23:25:31 +0100 Subject: [PATCH] tweet now contains max number of people present if more than 8 --- scripts/peoplecounter-realtime.sh | 10 +++++++--- scripts/upd_status.sh.d/tweet | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/peoplecounter-realtime.sh b/scripts/peoplecounter-realtime.sh index fd51048..a5cbe31 100755 --- a/scripts/peoplecounter-realtime.sh +++ b/scripts/peoplecounter-realtime.sh @@ -16,18 +16,22 @@ do echo "$p" > /run/peoplecounter if [ "$p" != "$oldp" ] then - logger $0 changed from $oldp to $p people + logger $(basename $0) changed from $oldp to $p people + if [ "$p" -gt "$oldp" ] + then + echo "$p" > /run/peoplecountermax + fi fi if [ "$state" = "offline" ] then state="online" - logger $0 people counter online + logger $(basename $0) people counter online fi else if [ "$state" = "online" ] then state="offline" - logger $0 people counter offline + logger $(basename $0) people counter offline fi fi sleep 10 diff --git a/scripts/upd_status.sh.d/tweet b/scripts/upd_status.sh.d/tweet index 1577d1a..8ad2699 100755 --- a/scripts/upd_status.sh.d/tweet +++ b/scripts/upd_status.sh.d/tweet @@ -15,7 +15,7 @@ $statusTag = '#statusUpdate'; // Set the messages to tweet when the status of the hackspace changes // %s is going to be replaced by the current time to avoid duplicate tweets on Twitter $messageOpen = "It's %s and we are open \o/ \ncome in and create something awesome =) \nhttps://Level2.lu/openingTimes"; -$messageClosed = "We just closed our doors at %s \nSee you very soon... \nhttps://Level2.lu/openingTimes"; +$messageClosed = "We just closed our doors at %s \n%sSee you very soon... \nhttps://Level2.lu/openingTimes"; require_once('TwitterAPIExchange.php'); @@ -49,7 +49,19 @@ if ( $currentStatus != $previousStatus ) { break; case 'closed': - $status = sprintf( $messageClosed, date( 'H:i' ) ); + $peopleMax=""; + if($peopleMax=file_get_contents("/var/run/peoplecountermax")) { + $peopleMax=str_replace("\n", '', $peopleMax); + file_put_contents("/var/run/peoplecountermax","0"); + if($peopleMax>8) { // only write this info if the place has been quite busy + $peopleMax="There were up to $peopleMax hackers today.\n"; + } else { + $peopleMax=""; + } + } else { + $peopleMax=""; + } + $status = sprintf( $messageClosed, date( 'H:i' ), $peopleMax ); break; }