Skip to content

Instantly share code, notes, and snippets.

@sebskuse
Created May 21, 2012 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebskuse/2762933 to your computer and use it in GitHub Desktop.
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.
<?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