Created
December 22, 2012 16:31
-
-
Save YarekTyshchenko/4359758 to your computer and use it in GitHub Desktop.
Hacky script to get o2's allowence stats when tethering
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 | |
date_default_timezone_set('Europe/London'); | |
$balance = @file_get_contents('http://wap.o2.co.uk/mybalance') or die('No Connection'); | |
$result = simplexml_load_string($balance); | |
$output = array(); | |
foreach($result->body->div as $div) { | |
$jackpot = false; | |
foreach($div->attributes() as $c => $k) { | |
if((string)$c === 'class' && (string)$k === 'm4') { | |
$jackpot = true; | |
} | |
} | |
if($jackpot){ | |
$output[] = $div; | |
} | |
} | |
$array = (Array)$output[1]; | |
$allowence = $array['span'][1]; | |
$used = $array['span'][3]; | |
$remaining = $array['span'][5]; | |
$date = date('d'); | |
$daysInMonth = date('t'); | |
$daysInLastMonth = date('t', strtotime('-1 month')); | |
if($date < 7) { | |
$allDays = $daysInLastMonth; | |
$today = $allDays-6+$date; | |
} else { | |
$allDays = $daysInMonth; | |
$today = $date-6; | |
} | |
$daysLeft = $allDays-$today+1; | |
$dataLeft = $allowence-$used; | |
$dayLeft = ($dataLeft/$daysLeft); | |
$daySpent = ($used/$today); | |
if($dayLeft == 0){ | |
$percentToday = '-.--%'; | |
} else { | |
$percentToday = number_format(100/($dayLeft/$daySpent),2).'%'; | |
} | |
echo 'Updated : '.date('D d H:i:s',time()).PHP_EOL; | |
echo PHP_EOL; | |
echo 'Allowance : '.$allowence.PHP_EOL; | |
echo 'Used : '.$used.PHP_EOL; | |
echo 'Remaining : '.$remaining.PHP_EOL; | |
echo PHP_EOL; | |
echo 'Daily Stats'.PHP_EOL; | |
echo '==========='.PHP_EOL; | |
echo 'Days : '.$allDays.'/'.$today.PHP_EOL; | |
echo '% Days : '.@number_format(100/($allDays/$today)).'%'.PHP_EOL; | |
echo 'Daily : '.@number_format($dayLeft,3).' MB'.PHP_EOL; | |
echo 'Spent : '.@number_format($daySpent,3).' MB'.PHP_EOL; | |
echo '% Today : '.$percentToday.PHP_EOL; | |
echo '% Total : '.@number_format(100/($allowence/$used), 2).'%'.PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment