Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('TwitterAPIExchange.php');
- require_once('Memory.php');
- date_default_timezone_set("UTC");
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- $memory = Memory::getInstance();
- if($memory->active()){
- //$events = $memory->forget('_events');
- $events = $memory->get('_events');
- }
- if(!$events){
- $settings = array(
- 'oauth_access_token' => "",
- 'oauth_access_token_secret' => "",
- 'consumer_key' => "",
- 'consumer_secret' => ""
- );
- $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
- $getfield = '?screen_name=jagexclock&count=30';
- $requestMethod = 'GET';
- $twitter = new TwitterAPIExchange($settings);
- $rawTweets = json_decode($twitter->setGetfield($getfield)
- ->buildOauth($url, $requestMethod)
- ->performRequest());
- $events = array();
- foreach($rawTweets as $rawTweet){
- $event = new stdClass();
- $districts = array();
- $rawTweet->created_at = preg_replace("/\+0000 /","", $rawTweet->created_at);
- $event->time = new DateTime();
- $event->time->setTimestamp(strtotime($rawTweet->created_at));
- if(preg_match("/in the ([a-zA-Z]{1,9}) and ([a-zA-Z]{1,9}) districts/", $rawTweet->text, $districts)){
- $event->text = "Prifddinas: {$districts[1]} and {$districts[2]}";
- $event->districts = array($districts[1],$districts[2]);
- $event->type = "prifddinas";
- } else if (preg_match("/Wilderness Warbands/", $rawTweet->text)) {
- $event->text = "Warbands in 15m";
- $event->type = "warband";
- } else {
- continue;
- }
- $events[] = $event;
- }
- $now = new DateTime();
- $yesterday = new DateTime();
- $yesterday->modify('-1 day');
- $yesterdayMidnight = new DateTime();
- $yesterdayMidnight->setTimestamp(strtotime($yesterday->format("d-m-Y ") . "0:00:00"));
- //caches
- $catchTime = clone $yesterdayMidnight;
- $catchTime->modify('-5 minutes');
- while($catchTime < $now){
- $event = new stdClass();
- $event->type = "cache";
- $event->text = "Guthix Cache in 5m";
- $event->time = clone $catchTime;
- $events[] = $event;
- $catchTime->modify('+3 hours');
- }
- //Goebies
- $goebiesTime = clone $yesterdayMidnight;
- $goebiesTime->modify('-10 minutes');
- while($goebiesTime < $now){
- $event = new stdClass();
- $event->type = "goebies";
- $event->text = "Goebies Supply Run in 15m";
- $event->time = clone $goebiesTime;
- $events[] = $event;
- $goebiesTime->modify('+12 hours');
- }
- usort($events, function($a, $b) {
- $ad = $a->time;
- $bd = $b->time;
- if ($ad == $bd) {
- return 0;
- }
- return $ad > $bd ? -1 : 1;
- });
- if($memory->active()){
- $memory->set('_events',$events,60);
- }
- }
- echo json_encode($events);
Advertisement
Add Comment
Please, Sign In to add comment