Created
September 27, 2016 23:32
-
-
Save kmark/f305092d36410972bbb66f8c3046dec8 to your computer and use it in GitHub Desktop.
Counts cumulative downloads of an Xposed module from both the Xposed repo and GitHub. Beware of GitHub rate limits.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$repoId = 'com.versobit.kmark.xhangouts'; | |
$ghId = 'kmark/XHangouts'; | |
preg_match_all('/([\\d,]+) in total/m', fgc('http://repo.xposed.info/module/' . $repoId), $matches); | |
$repoCount = array_reduce($matches[1], function($carry, $item) { | |
return $carry + str_replace(',', '', trim($item)); | |
}, 0); | |
echo number_format($repoCount) . ' downloads from the Xposed repository.' . PHP_EOL; | |
$ghCount = array_sum(array_map(function($release) { | |
$assets = array_filter(json_decode(fgc($release->assets_url)), function($asset) { | |
return $asset->content_type == 'application/vnd.android.package-archive'; | |
}); | |
return array_reduce($assets, function($carry, $asset) { | |
return $carry + $asset->download_count; | |
}, 0); | |
}, json_decode(fgc('https://api.github.com/repos/' . $ghId . '/releases')))); | |
echo number_format($ghCount) . ' downloads from GitHub.' . PHP_EOL; | |
echo number_format($repoCount + $ghCount) . ' total downloads.' . PHP_EOL; | |
function fgc($url) { | |
return file_get_contents($url, null, stream_context_create([ | |
'http' => [ | |
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2868.3 Safari/537.36', | |
], | |
])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment