Advertisement
Guest User

Untitled

a guest
Apr 24th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. //need to add a time_since_new_data to handle time outs
  3. //need to add number_of_responses_since_rulesUpdate
  4. ////will use this to run the rule_utility
  5. //purpose:
  6. //connects to gnip and collects our data
  7.  
  8. include_once('gnip_functions.php');
  9.  
  10. class Collector
  11. {
  12. protected $user;
  13. protected $pass;
  14. protected $stream_url;
  15.  
  16. public $time_since;
  17. public $records_since;
  18.  
  19.  
  20.  
  21. function __construct($u, $p)
  22. {
  23. $this->user = $u;
  24. $this->pass = $p;
  25. $this->stream_url = "https://stream.gnip.com:443/accounts/account_holder/publishers/twitter/streams/track/prod.json";
  26. $this->time_since = time();
  27. }
  28.  
  29. public function connectGnip()
  30. {
  31. $ch = curl_init();
  32. curl_setopt_array($ch, array(
  33. CURLOPT_URL => $this->stream_url,
  34. CURLOPT_ENCODING => "gzip",
  35. CURLOPT_FOLLOWLOCATION => true,
  36. CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
  37. CURLOPT_USERPWD => $this->user.":".$this->pass,
  38. //CURLOPT_WRITEFUNCTION => "data_manager",
  39. CURLOPT_COOKIEFILE => 'gnip_cookies',
  40. CURLOPT_CONNECTTIMEOUT => 0,
  41. CURLOPT_VERBOSE => true // uncomment for curl verbosity
  42.  
  43. ));
  44. curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, "data_manager"));
  45. curl_exec($ch);
  46. curl_close($ch);
  47. }
  48.  
  49. function spawnScripts()
  50. {
  51. exec('php rule_utility.php');
  52. return true;
  53. }
  54.  
  55. public function data_manager($ch, $data)
  56. {
  57. if($this->records_since > 40)
  58. {
  59. $this->spawnScripts();
  60. $this->records_since = 0;
  61. }
  62.  
  63. $tmp = json_decode($data);
  64. if(isset($tmp->{'body'}))
  65. { storeTweetToBuffer($data); }
  66. else
  67. { $this->spawnScripts(); }
  68.  
  69. $this->records_since += 1;
  70. return strlen($data); // required to return the length of the data passed to it
  71. }
  72. }
  73.  
  74.  
  75.  
  76.  
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement