Created
May 21, 2012 15:32
-
-
Save sebskuse/2762933 to your computer and use it in GitHub Desktop.
Simple PHP-CLI script to get number of ratings & stars of an app in the AppStore. Takes args from commandline & preset array.
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
<?php | |
error_reporting(0); | |
// Array of appstore ID's to always look up | |
$idArray = array( | |
"428243918", | |
"442713833" | |
); | |
$arguments = array_merge($idArray, array_slice($argv, 1) ); | |
foreach($arguments as $id) parseID($id); | |
function parseID($id){ | |
$data = file_get_contents("http://itunes.apple.com/gb/app/id" . $id); | |
if(!$data) { | |
echo "Unknown ID " . $id; | |
return; | |
} | |
// Get title. | |
preg_match("/<title>(?P<title>.*?)<\/title>/i", $data, $titleMatches); | |
// Get ratings. | |
preg_match("/<div class=\'rating\' role='img' tabindex='-1' aria-label='(?P<stars>.*?), (?P<ratings>\d+)\s+Ratings'>/i", $data, $matches); | |
echo "{$titleMatches['title']}: {$matches['ratings']} ratings ({$matches['stars']})\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment