Skip to content

Instantly share code, notes, and snippets.

@mramsden
Forked from sebskuse/appstore.php
Created May 28, 2012 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mramsden/2819846 to your computer and use it in GitHub Desktop.
Save mramsden/2819846 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";
}
#!/usr/bin/env ruby
require 'open-uri'
DEFAULT_IDS = [ "428243918", "442713833" ]
ids = DEFAULT_IDS | ARGV
ids.each do |appstore_id|
data = open("http://itunes.apple.com/gb/app/id#{appstore_id}").read
if data.nil?
puts "Unknown id #{appstore_id}\n"
else
title = %r(<title>(?P<title>.*?)<\/title>).match(data)[:title]
rating = %r(<div class=\'rating\' role='img' tabindex='-1' aria-label='(?P<stars>.*?), (?P<ratings>\d+)\s+Ratings'>).match(data)
puts "#{title}: #{rating[:ratings]} ratings " << "(" + ("*" * rating[:stars]) + ")"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment