illwieckz

unvanquished download counter

May 28th, 2019
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. [illwieckz:~/dev/unvanquished-download-counter] $ cat count
  2. #! /bin/sh
  3.  
  4. getIndieDb () {
  5. curl -s "https://www.indiedb.com/games/${1}/stats" \
  6. | grep '<h5>Downloads Total</h5>' -A2 \
  7. | tail -n1 \
  8. | sed -e 's/[^0-9]*//g'
  9. }
  10.  
  11. getGitHub () {
  12. curl -s https://api.github.com/repos/${1}/releases \
  13. | grep '"download_count":' \
  14. | sed -e 's/[^0-9]*//g' \
  15. | paste -s -d+ - \
  16. | bc
  17. }
  18.  
  19. getSourceForge () {
  20. epoch="$(date '+%Y-%m-%d' -d@0)"
  21. today="$(date '+%Y-%m-%d')"
  22. curl -s "https://sourceforge.net/projects/${1}/files/stats/json?start_date=${epoch}&end_date=${today}" \
  23. | tr ',' '\n' \
  24. | grep '"time": {"downloads":' \
  25. | sed -e 's/[^0-9]*//g'
  26.  
  27. }
  28.  
  29. getSum () {
  30. echo "${@}" \
  31. | tr ' ' '\n' \
  32. | paste -s -d+ - \
  33. | bc
  34. }
  35.  
  36. indiedb_all="$(getIndieDb 'unvanquished')"
  37. github_game="$(getGitHub 'Unvanquished/Unvanquished')"
  38. github_updater="$(getGitHub 'Unvanquished/updater')"
  39. sourceforge_all="$(getSourceForge 'unvanquished')"
  40. sum_all="$(getSum "${indiedb_all}" "${github_game}" "${github_updater}" "${sourceforge_all}")"
  41.  
  42. cat <<EOF
  43. {
  44. {
  45. "description": "Unvanquished game on GitHub",
  46. "proof-url": "https://www.somsubhra.com/github-release-stats/?username=Unvanquished&repository=Unvanquished",
  47. "key": "github/game",
  48. "count": ${github_game},
  49. },
  50. {
  51. "description": "Unvanquished updater on GitHub",
  52. "proof-url": "https://www.somsubhra.com/github-release-stats/?username=Unvanquished&repository=updater",
  53. "key": "github/updater",
  54. "count": ${github_updater},
  55. },
  56. {
  57. "description": "Unvanquished files on SourceForge",
  58. "proof-url": "https://sourceforge.net/projects/unvanquished/files/stats/timeline?dates=2012-02-26+to+2019-05-28",
  59. "key": "sourceforge/all",
  60. "count": ${sourceforge_all},
  61. },
  62. {
  63. "description": "Unvanquished files on Indie DB",
  64. "proof-url": "https://www.indiedb.com/games/unvanquished/stats",
  65. "key": "indiedb/game",
  66. "count": ${indiedb_all},
  67. },
  68. {
  69. "description": "Unvanquished files total"
  70. "key": "summary"
  71. "count": "${sum_all}"
  72. }
  73. }
  74. EOF
  75.  
  76. #EOF
  77.  
  78. [illwieckz:~/dev/unvanquished-download-counter] $ ./count
  79. {
  80. {
  81. "description": "Unvanquished game on GitHub",
  82. "proof-url": "https://www.somsubhra.com/github-release-stats/?username=Unvanquished&repository=Unvanquished",
  83. "key": "github/game",
  84. "count": 24500,
  85. },
  86. {
  87. "description": "Unvanquished updater on GitHub",
  88. "proof-url": "https://www.somsubhra.com/github-release-stats/?username=Unvanquished&repository=updater",
  89. "key": "github/updater",
  90. "count": 3313,
  91. },
  92. {
  93. "description": "Unvanquished files on SourceForge",
  94. "proof-url": "https://sourceforge.net/projects/unvanquished/files/stats/timeline?dates=2012-02-26+to+2019-05-28",
  95. "key": "sourceforge/all",
  96. "count": 1337688,
  97. },
  98. {
  99. "description": "Unvanquished files on Indie DB",
  100. "proof-url": "https://www.indiedb.com/games/unvanquished/stats",
  101. "key": "indiedb/game",
  102. "count": 2969,
  103. },
  104. {
  105. "description": "Unvanquished files total"
  106. "key": "summary"
  107. "count": "1368470"
  108. }
  109. }
Add Comment
Please, Sign In to add comment