PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/package/app/app/scripts/uv_summary_insert.php

https://bitbucket.org/pandaos/kaltura
PHP | 57 lines | 43 code | 14 blank | 0 comment | 13 complexity | f2179ef2051f5e786cfc1e31c8a1a7dc MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-3.0, JSON, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. function usage()
  3. {
  4. echo "\nusage: uv_summary_insert [cookie/ip] [date yyyy-mm-dd] [path - may use wildcard]\n";
  5. die;
  6. }
  7. $uv_type = @$argv[1];
  8. if ($uv_type == "cookie")
  9. $table_name = "unique_visitors_cookie";
  10. else if ($uv_type == "ip")
  11. $table_name = "unique_visitors_ip";
  12. else
  13. {
  14. echo "invalid unique visitors type [$uv_type]- use either cookie or ip\n";
  15. usage();
  16. }
  17. $date = @$argv[2];
  18. $path = @$argv[3];
  19. if (strlen($date) != 10 || !$path)
  20. {
  21. usage();
  22. }
  23. $files = glob($path);
  24. echo "delete from $table_name where date='$date';\n";
  25. foreach($files as $file)
  26. {
  27. $data = file_get_contents($file);
  28. $lines = explode("\n", $data);
  29. foreach($lines as $line)
  30. {
  31. if ($line == "")
  32. continue;
  33. if ($uv_type == "ip")
  34. {
  35. $value = ip2long($line);
  36. if ($value >= 0x80000000) $value -= 0x100000000;
  37. }
  38. else
  39. $value = $line;
  40. echo "insert into $table_name values('$value','$date');\n";
  41. }
  42. }
  43. ?>