/** * The Grand Collecter of Tweets * * Uses FilterTrackConsumer based on Phirehose library to connect to the Twitter Streaming API */ public function trackStream() { $this->log('starting tracker', 'tracker'); if (defined('LOG_DIR')) { ini_set('error_log', LOG_DIR . 'tracker.log'); } $this->db->exec('set wait_timeout = 43200'); $tweetQueue = new TweetQueue($this->db); $sc = new FilterTrackConsumer(TWITTER_OAUTH_TOKEN, TWITTER_OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setTweetQueue($tweetQueue); $sc->setTrack(array('#fb')); $sc->consume(); // we only reach here on error $this->log('exiting tracker', 'tracker'); }
* Enqueue each status * * @param string $status */ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being * enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); if (is_array($data) && isset($data['user']['screen_name'])) { print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n"; } } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", "TSqgx84SucxJ3yQ8gNCnlNSzY"); //5ZpZK45txurjRWA0jAMS6ps96 define("TWITTER_CONSUMER_SECRET", "TuXyHGbW82dM5i1fXTnulgmcS1ln25yR0MCPe9njCpUmGNtYOK"); //4cp43JzQUl155AIpYrUvWsLqHyhlUzXFaABUq7M487kW0hh7MK // The OAuth data for the twitter account define("OAUTH_TOKEN", "3172457999-cM13Lq49BI9ZCJJTtGjFQO7EQWIsLONaX4q2EjR"); //747025008-mlocAiUlJWz7U7MPohxhsv8rPScHCgbuAHI6Zs4C define("OAUTH_SECRET", "3Pf25ggRqUmr2nwu0T0qgPkRO3elsXUbTPkcJ6vKclgFX"); //fXQX2uyOvPayEpDtGedvSPHWfgvlqCsHvwVgsYT53PycQ // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setTrack(array('morning', 'goodnight', 'hello', 'the')); $sc->consume();
*/ public function enqueueStatus($status) { print_r($status); $this->tweetCounter++; $filePath = './tweet-' . time() . '_' . self::$tweetCounter . '.tweet'; file_put_contents($filePath, $status); } } define("TWITTER_CONSUMER_KEY", $tw_consumer_key); define("TWITTER_CONSUMER_SECRET", $tw_consumer_secret); // The OAuth data for the twitter account define("OAUTH_TOKEN", $tw_token); define("OAUTH_SECRET", $tw_token_secret); // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setLocations(array(array(52.516667 - 0.01, 13.383333 - 0.01, 52.516667 + 0.01, 13.383333 + 0.01))); $sc->consume(); /* if($mainLng==999 && $mainLng==999 && $words[0]["word"]!="*"){ $qq = ""; for($i=0 ; $i<count($words) ; $i++){ $qq = $qq . $words[$i]["word"]; if($i<count($words)-1){ $qq = $qq . " OR "; } } $query = "q=" . $qq . "&result_type=recent&count=100";
*/ class FilterTrackConsumer extends OauthPhirehose { /** * Enqueue each status * * @param string $status */ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being * enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); if (is_array($data) && isset($data['user']['screen_name'])) { print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n"; } } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", "ot0tUgarTYxEBCQrRynDgdMKr"); define("TWITTER_CONSUMER_SECRET", "iUtFcLdY2fDq9jGqIQLfIaXG8ROYHAKv3OMNOtJIVzDZsWztoY"); // The OAuth data for the twitter account define("OAUTH_TOKEN", "2816508089-1ImNswhZ0uEhq7xBwUAmZpF5hfGDcez4qbVokqN"); define("OAUTH_SECRET", "sf4EVHZ5A3UEv0Tf1Wun4w9jcQq7sHKfUkQUEZSjioXxh"); // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setLocations(array(array(12.5685, 55.6754, 12.5913, 55.6882))); $sc->consume();
* Enqueue each status * * @param string $status */ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being * enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); if (is_array($data) && isset($data['user']['screen_name'])) { print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n"; $this->push_data_to_db($data); //$this->AutoTranslate($data); } } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", "your twitter consumer key"); define("TWITTER_CONSUMER_SECRET", "Your twitter consumer secret"); // The OAuth data for the twitter account define("OAUTH_TOKEN", "your twitter application token"); define("OAUTH_SECRET", "your twitter application secret"); // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setLocations(array(array(-0.5103, 51.2868, 0.334, 51.6923))); $sc->setTrack(array('@5liveSport', '@SW_Trains', '@GiveBloodNHS', '@BBCSport', '@bbcweather', '@ukhomeoffice', '@AboutTheBBC', '@EnvAgency', '@NHSEnglandLDN', '@TimeOutLondon', '@CityofLdnOnt', '@BBC', '@GOVUK', '@cityoflondon', '@bbc5live', '@SkyNews', '@BBCBreaking', '@FinancialTimes', '@bbcworldservice', '@BBCWorld', '@BBCNews', '@LondonSHP', '@metpoliceuk', '#LondonTraffic', '@londontraffic', '@TfLTrafficNews', '@LDNTraffic', '@WazeTrafficLON', '@TfLBusAlerts')); $sc->setFollow(array(47331384, 31129844, 22906929, 1155611857, 338237494, 3216970444.0, 400051029)); $sc->consume();
<?php require_once('../lib/Phirehose.php'); /** * Example of using Phirehose to display a live filtered stream using track words */ class FilterTrackConsumer extends Phirehose { /** * Enqueue each status * * @param string $status */ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being * enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); if (is_array($data) && isset($data['user']['screen_name'])) { print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n"; } } } // Start streaming $sc = new FilterTrackConsumer('newshorts', 'GD_00bouer', Phirehose::METHOD_FILTER); $sc->setTrack(array('sfsuperbowl', 'tweening')); $sc->consume();
$collection->insert($refinedData); } //print $refinedData['user_screen_name'] . ': ' . $refinedData['text'] . "\n"; /*$myFile = fopen('tweetsWithUppsala.json', 'a'); fwrite($myFile, $refinedJSON . "\n"); fclose($myFile);*/ } } function coordInUppsala($coordinates) { if ($coordinates[0] > 17.51 && $coordinates[0] < 17.8) { if ($coordinates[1] > 59.79 && $coordinates[1] < 59.91) { return true; } else { return false; } } else { return false; } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", "UhAWWHnOa8pHU78FgYaHmWEQN"); define("TWITTER_CONSUMER_SECRET", "qaXWnC2aQ3BmABbMYVDiOQ2EXij9SOBauVIx25YLbuKo47srhO"); // The OAuth data for the twitter account define("OAUTH_TOKEN", "3150881842-bxomhSUyXuvGy12WAdq5uBz7OUwPi9qwMuebza6"); define("OAUTH_SECRET", "PebJAPeR2ej1fkzRg8nZfVffNCgOQpuUgeXTC8eFT3T9K"); // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setTrack(array('uppsala')); $sc->setLocations(array(array(17.51, 59.79, 17.8, 59.91))); $sc->consume();
*/ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being * enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); $refinedData = array('created_at' => $data['created_at'], 'tweet_id' => $data['id_str'], 'text' => urldecode($data['text']), 'user_id' => $data['user']['id_str'], 'user_name' => $data['user']['name'], 'user_screen_name' => $data['user']['screen_name'], 'coordinates' => $data['coordinates'], 'place' => $data['place'], 'language' => $data['lang'], 'retweeted' => $data['retweeted']); print $refinedData['user_screen_name'] . ': ' . $refinedData['text'] . "\n"; $refinedJSON = json_encode($refinedData, true); $myFile = fopen('tweetsLocation.json', 'a'); fwrite($myFile, $refinedJSON . "\n"); fclose($myFile); $m = new MongoClient(); $db = $m->SocialMedia; $collection = $db->tweetsByLocation; $collection->insert($refinedData); } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", "UhAWWHnOa8pHU78FgYaHmWEQN"); define("TWITTER_CONSUMER_SECRET", "qaXWnC2aQ3BmABbMYVDiOQ2EXij9SOBauVIx25YLbuKo47srhO"); // The OAuth data for the twitter account define("OAUTH_TOKEN", "3150881842-bxomhSUyXuvGy12WAdq5uBz7OUwPi9qwMuebza6"); define("OAUTH_SECRET", "PebJAPeR2ej1fkzRg8nZfVffNCgOQpuUgeXTC8eFT3T9K"); // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setLocations(array(array(17.51, 59.79, 17.8, 59.91))); $sc->consume();
<?php require_once '../lib/Phirehose.php'; /** * Example of using Phirehose to display a live filtered stream using geo locations */ class FilterTrackConsumer extends Phirehose { /** * Enqueue each status * * @param string $status */ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being * enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); if (is_array($data) && isset($data['user']['screen_name'])) { print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n"; } } } // Start streaming $sc = new FilterTrackConsumer('username', 'password', Phirehose::METHOD_FILTER); $sc->setLocations(array(array(-122.75, 36.8, -121.75, 37.8), array(-74, 40, -73, 41))); $sc->consume();
require_once '../vendor/fennb/phirehose/lib/Phirehose.php'; require_once '../vendor/fennb/phirehose//lib/OauthPhirehose.php'; /** * Example of using Phirehose to display a live filtered stream using track words */ class FilterTrackConsumer extends OauthPhirehose { /** * Enqueue each status * * @param string $status */ public function enqueueStatus($status) { // For demonstrative purposes, write to STDOUT $data = json_decode($status, true); if (is_array($data) && isset($data['user']['screen_name'])) { print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n"; } } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", ""); define("TWITTER_CONSUMER_SECRET", ""); // The OAuth data for the twitter account define("OAUTH_TOKEN", ""); define("OAUTH_SECRET", ""); // Start streaming $streamConsumer = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $streamConsumer->setTrack(array('endorses sanders', 'endorses bernie', 'endorses bernie sanders', 'endorsed sanders', 'endorsed bernie', 'endorsed bernie sanders')); $streamConsumer->consume();
$substr = explode(" ", $text); foreach ($substr as $word) { foreach ($this->getTrack() as $motcle) { if ($word == $motcle) { $mots_cles = $word; } } } try { include 'connect.inc.php'; $req = $bdd->prepare("INSERT into tweet(message, localisation, date, mots_cles) values (:message, :localisation, :date, :mots_cles);"); $ok = $req->execute(array('message' => $text, 'localisation' => $localisation, 'date' => $date_r, 'mots_cles' => $mots_cles)); } catch (PDOException $e) { echo "<BR/>" . $e . "<BR/>"; } } if ($this->tweet_count >= 5) { exit; } } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", "fxPiWdMXW0oHk9OLwIavMn3ns"); define("TWITTER_CONSUMER_SECRET", "eCRPfxT3bRG490KWPcbpO6F1RX4FdXCW8c9HquFxOCsCTP2dPH"); // The OAuth data for the twitter account define("OAUTH_TOKEN", "763684332-g2P4tnD0xlXzwOc4cZFILrPkIUXOuU5PTiXMD2S6"); define("OAUTH_SECRET", "sIFafoYoFchI8KF4i3QSOXPzvi4L63lvnv2HRTtnz8pQP"); // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setTrack(array('#attentat', '#catastrophe', '#désastre', '#alerte', '#secours', '#accident', '#rip', '#sos')); $sc->consume();
* Enqueue each status * * @param string $status */ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being * enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); if (is_array($data) && isset($data['user']['screen_name'])) { print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n"; $this->push_data_to_db($data); // $this->AutoTranslate($data); } } } // The OAuth credentials you received when registering your app at Twitter define("TWITTER_CONSUMER_KEY", "your twitter consumer key"); define("TWITTER_CONSUMER_SECRET", "Your twitter consumer secret"); // The OAuth data for the twitter account define("OAUTH_TOKEN", "your twitter application token"); define("OAUTH_SECRET", "your twitter application secret"); // Start streaming $sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER); $sc->setLocations(array(array(10.18, 56.142, 10.234, 56.1721))); $sc->setTrack(array('@StiftenAGF', '@jpaarhus', '#Aarhus', '@AarhusKultur', '@smagaarhus', '@AarhusNyheder', '@AarhusPortaldk', '@Aarhus2017', '@OpenDataAarhus', '@aarhusupdate', '@AskVest', '@SundhedOgOmsorg', '@ArhusVejr', '@aarhus_ints', '@AGFFANdk', '@AarhusCykelby', '@VisitAarhus', '@larshaahr')); $sc->setFollow(array(3601200017.0, 3370065087.0, 3330970365.0, 2911388001.0, 2706568231.0, 2647614595.0, 2201213730.0, 1324132976, 1065597596, 210987829, 159110346, 112585923, 77749562, 38227253, 36040150)); $sc->consume();
// Request list of active campaign slugs from Wordpress $response = $this->doPostRequest('tdr_promotions_list_active_campaign_hashtags'); $contest_scrape_terms = json_decode($response); // Decode JSON response if ($contest_scrape_terms != $this->getTrack()) { // Update filter terms used for scrape if they have changed $this->setTrack($contest_scrape_terms); } } /** * Enqueue each status * * @param string $status */ public function enqueueStatus($status) { // Send collected tweet to Wordpress for processing // print 'status found' . "\n"; // DEBUGGING: show when tweets are found $this->doPostRequest('tdr_promotions_twitter_scrape', $status); } } // Start streaming // Get twitter username and password from Command line arguments $options = getopt("u:p:", array("username:"******"password:")); $twitter_username = $options['username']; $twitter_password = $options['password']; // Setup Scraper $sc = new FilterTrackConsumer($twitter_username, $twitter_password, 60 * 60 * 12); // Set twitter credentials & filter refresh interval // Begin Scraping $sc->consume();