-
-
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.
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"; | |
} |
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 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