PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/funkatron_twitterpublic.php

https://github.com/funkatron/twitter-stats-tracker
PHP | 51 lines | 22 code | 19 blank | 10 comment | 1 complexity | fbb975a7b3b91f9dd30fa9afc09896e4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #!/usr/bin/php
  2. <?php
  3. $url = 'http://twitter.com/statuses/public_timeline.json';
  4. // $url = 'public_timeline.json';
  5. $json = file_get_contents($url);
  6. if (!$json) {
  7. trigger_error("getting public timeline failed -- exiting", E_USER_ERROR);
  8. }
  9. $pubtweets->docs = json_decode($json);
  10. $newjson = json_encode($pubtweets);
  11. // $json = json_encode(json_decode($json));
  12. echo "<pre>"; echo print_r($json, true); echo "</pre>";
  13. $cdb_url = 'http://127.0.0.1:5984/publictweets/_bulk_docs';
  14. $http = new HttpRequest($cdb_url, HttpRequest::METH_POST);
  15. $http->setContentType('application/json');
  16. $http->setRawPostData($newjson);
  17. $http->send();
  18. // update view
  19. $url = 'http://127.0.0.1:5984/publictweets/_view/sourcetotal/total?group=true';
  20. $json_counts = file_get_contents($url);
  21. $counts = json_decode($json_counts);
  22. foreach($counts->rows as &$row) {
  23. $row->key = strip_tags(stripslashes($row->key));
  24. // echo "<pre>"; echo print_r($row->key, true); echo "</pre>";
  25. }
  26. // echo "<pre>"; echo print_r($counts, true); echo "</pre>";
  27. $json_counts = json_encode($counts);
  28. // echo "<pre>"; echo print_r($json_counts, true); echo "</pre>";
  29. // $json_counts = strip_tags(stripslashes($json_counts));
  30. file_put_contents('/var/www/twittersource.info/htdocs/twitter-source-stats.json', $json_counts);
  31. // echo "<pre>"; echo print_r($http->getResponseMessage(), true); echo "</pre>";
  32. // echo "<pre>"; echo print_r($json, true); echo "</pre>";