#! /usr/pkg/bin/perl -w #! /usr/pkg/bin/curl # Autofetch stars # This program fetches the number of stars for a given application use strict; use warnings; my $result = -1; my $store; my $coCode; my $appId; my $counter = 0; my $currentSoftware; my $temp; my $flag = 0; print "Content-type: text/html\n\n"; splitVars(); $currentSoftware = $appId; $store = 143441;getReviews(); print $result; sub splitVars{ my $item = ""; my $riz = $ENV{'QUERY_STRING'}; if($riz){ my @rizray = split("&", $riz); foreach $item (@rizray){ if(index($item, "id", 0) >= 0){ $appId = substr($item, index($item, "id", 0)+3, length($item)); } elsif(index($item, "country", 0) >= 0){ $coCode = substr($item, index($item, "country", 0) + 8, length($item)); } } } } sub getReviews { my $riz = "test"; $riz = `curl -s -A "iTunes/4.2 (Macintosh; U; PPC Mac OS X 10.2" -H "X-Apple-Store-Front: $store-1" 'http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=$currentSoftware&pageNumber=0&sortOrdering=2&type=Purple+Software'`; $riz = substr($riz, index($riz, 'Average rating for all versions: ', 0), 300); $riz = substr($riz, index($riz, "rightInset=\"6\" alt=\"", 0)+20, 100); $riz = substr($riz, 0, index($riz, '"', 0)); if(length($riz) != 0){ if($result == -1){$result = substr($riz, 0, 1);} else{$result += int(substr($riz, 0, 1));} if(index($riz, 'and a half', 1) > 0){$result += 0.5;} } }