#!/usr/bin/php 'xxxx', 'oauth_access_token_secret' => 'yyyy', 'consumer_key' => 'xxxxx', 'consumer_secret' => 'yyyyy' ); */ require_once('twittertokens.php'); /* put the tokens inside separate file which is in .gitignore */ /** URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/ $url = 'https://api.twitter.com/1.1/statuses/update.json'; $requestMethod = 'POST'; // Get the current and previous status from the parameters handed over to the script $currentStatus = $argv[1]; $previousStatus = $argv[2]; // Chack if the status has changed if ( $currentStatus != $previousStatus ) { // based on the new status, define the message to tweet switch ( $currentStatus ) { case 'open': $status = sprintf( $messageOpen, date( 'H:i' ) ); break; case 'closed': $peopleMax=""; if($peopleMax=file_get_contents("/var/cache/peoplecountermax")) { $peopleMax=str_replace("\n", '', $peopleMax); file_put_contents("/var/cache/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; } // POST fields required by the URL above. See relevant docs as above $postfields = array( 'status' => $status ); // Perform a POST request and echo the response $twitter = new TwitterAPIExchange($settings); // build the tweet and send it out $twitter ->buildOauth($url, $requestMethod) ->setPostfields($postfields) ->performRequest(); }