Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //need to add a time_since_new_data to handle time outs
- //need to add number_of_responses_since_rulesUpdate
- ////will use this to run the rule_utility
- //purpose:
- //connects to gnip and collects our data
- include_once('gnip_functions.php');
- class Collector
- {
- protected $user;
- protected $pass;
- protected $stream_url;
- public $time_since;
- public $records_since;
- function __construct($u, $p)
- {
- $this->user = $u;
- $this->pass = $p;
- $this->stream_url = "https://stream.gnip.com:443/accounts/account_holder/publishers/twitter/streams/track/prod.json";
- $this->time_since = time();
- }
- public function connectGnip()
- {
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $this->stream_url,
- CURLOPT_ENCODING => "gzip",
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
- CURLOPT_USERPWD => $this->user.":".$this->pass,
- //CURLOPT_WRITEFUNCTION => "data_manager",
- CURLOPT_COOKIEFILE => 'gnip_cookies',
- CURLOPT_CONNECTTIMEOUT => 0,
- CURLOPT_VERBOSE => true // uncomment for curl verbosity
- ));
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, "data_manager"));
- curl_exec($ch);
- curl_close($ch);
- }
- function spawnScripts()
- {
- exec('php rule_utility.php');
- return true;
- }
- public function data_manager($ch, $data)
- {
- if($this->records_since > 40)
- {
- $this->spawnScripts();
- $this->records_since = 0;
- }
- $tmp = json_decode($data);
- if(isset($tmp->{'body'}))
- { storeTweetToBuffer($data); }
- else
- { $this->spawnScripts(); }
- $this->records_since += 1;
- return strlen($data); // required to return the length of the data passed to it
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement