PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/bin/funkatron_twitterpublic_min.php

https://github.com/funkatron/twitter-stats-tracker
PHP | 51 lines | 32 code | 14 blank | 5 comment | 2 complexity | 45e379988a6154892271e7e50f1a1779 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. $json = file_get_contents($url);
  5. if (!$json) {
  6. trigger_error("getting public timeline failed -- exiting", E_USER_ERROR);
  7. }
  8. $pubtweets->docs = json_decode($json);
  9. foreach ($pubtweets->docs as &$doc) {
  10. $newdoc->_id = $doc->id;
  11. $newdoc->date = strtotime($doc->created_at);
  12. $newdoc->source = $doc->source;
  13. $doc = $newdoc;
  14. unset($newdoc);
  15. }
  16. $newjson = json_encode($pubtweets);
  17. echo "<pre>"; echo print_r($newjson, true); echo "</pre>";
  18. $cdb_url = 'http://127.0.0.1:5984/publictweets_sources/_bulk_docs';
  19. $http = new HttpRequest($cdb_url, HttpRequest::METH_POST);
  20. $http->setContentType('application/json');
  21. $http->setRawPostData($newjson);
  22. $http->send();
  23. /*
  24. update view
  25. */
  26. // $url = 'http://127.0.0.1:5984/publictweets_sources/_view/sourcetotal/total?group=true';
  27. $url = 'http://127.0.0.1:5984/publictweets_sources/_view/all/counts?group=true';
  28. $json_counts = file_get_contents($url);
  29. $counts = json_decode($json_counts);
  30. foreach($counts->rows as &$row) {
  31. $row->key = strip_tags(stripslashes($row->key));
  32. }
  33. echo "<pre>"; echo print_r($counts, true); echo "</pre>";
  34. $json_counts = json_encode($counts);
  35. if ($json_counts) {
  36. file_put_contents('/var/www/twittersource.info/htdocs/twitter-source-stats.json', $json_counts);
  37. }