Created
August 12, 2013 11:53
-
-
Save stephen-hill/6210221 to your computer and use it in GitHub Desktop.
This script will calculate the total price of everything on the Steam UK store. Designed to be run from the PHP CLI. Requires cURL.
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 | |
header('Content-Type: text/plain'); | |
$total = 0; | |
$id = 0; | |
$apps = array(); | |
set_time_limit(0); | |
// Get a list of all valid apps | |
$applist = file_get_contents('http://api.steampowered.com/ISteamApps/GetAppList/v2'); | |
$applist = json_decode($applist); | |
foreach ($applist->applist->apps as $app) | |
{ | |
if (is_int($app->appid)) | |
{ | |
$apps[$app->appid] = $app->name; | |
} | |
} | |
unset($applist); | |
krsort($apps); | |
echo "Last ID\tProgress\tTotal Price\tPHP Memory\tPeak Memory\n"; | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
foreach($apps as $id => $name) | |
{ | |
$ids = (string)$id; | |
try | |
{ | |
curl_setopt($curl, CURLOPT_URL, 'http://store.steampowered.com/api/appdetails/?cc=uk&appids=' . $id); | |
$data = curl_exec($curl); | |
$json = json_decode($data); | |
if (isset($json->$ids->data->price_overview->final) === true) | |
{ | |
$price = (int)$json->$ids->data->price_overview->final; | |
$total = $total + $price; | |
} | |
} | |
catch (Exception $e) {} | |
$progress = array_search($id, array_keys($apps)) . '/' . count($apps); | |
echo str_repeat(' ', 80) . "\r"; | |
echo $ids . "\t" . $progress . "\t" . number_format($total/100, 2) . ' GBP' . "\t" . number_format(intval(memory_get_usage()/1024)) . 'Kb' . "\t\t" . number_format(intval(memory_get_peak_usage()/1024)) . 'Kb' . "\r"; | |
gc_collect_cycles(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment