/** * 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();
* 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();
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();