More ADSL updates and fixes from live site

This commit is contained in:
Deon George
2013-11-15 21:05:22 +11:00
parent c66f2f14c4
commit a711e70b60
9 changed files with 118 additions and 229 deletions

View File

@@ -42,28 +42,39 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
echo " = Service: ".$so->name()."\n";
if ($so->plugin()->service_stats_collect AND $so->plugin()->service_stats_lastupdate < $date) {
// Start Session
$request = Request::factory($this->aso->stats_url)
->method('POST')
->post($this->login_user_field,$so->plugin()->service_username)
->post($this->login_pass_field,$so->plugin()->service_password)
->post('doLogin',1)
->post('submit','Login');
$debug = FALSE;
$request->client()->options($this->curlopts+array(
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number),
));
if (! $debug) {
// Start Session
$request = Request::factory($this->aso->stats_url)
->method('POST')
->post($this->login_user_field,$so->plugin()->service_username)
->post($this->login_pass_field,$so->plugin()->service_password)
->post('doLogin',1)
->post('submit','Login');
$response = $request->execute();
$data = $response->body();
$request->client()->options($this->curlopts+array(
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number),
));
if (! $data) {
// @todo Log into a log file
printf('Bad fetch for %s [%s]',$so->plugin()->service_number,$this->aso->stats_lastupdate);
#$html = new simple_html_dom();
#$html->load($data);
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.login.html',$so->plugin()->service_number,'login'));
continue;
$response = $request->execute();
$data = $response->body();
if (! $data) {
// Record some debugging if we are in verbose mode
if (Minion_CLI::options('verbose')) {
file_put_contents('/tmp/osb.response.txt',print_r($response,TRUE));
file_put_contents('/tmp/osb.request.txt',print_r($request,TRUE));
file_put_contents('/tmp/osb.data.txt',print_r($data,TRUE));
}
// @todo Log into a log file
printf('Bad fetch for %s [%s]',$so->plugin()->service_number,$this->aso->stats_lastupdate);
#$html = new simple_html_dom();
#$html->load($data);
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.login.html',$so->plugin()->service_number,'login'));
continue;
}
}
for ($servicedate=date('Y-m-d',strtotime($this->aso->stats_lastupdate.'+1 day'));
@@ -75,9 +86,13 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
if (strtotime($lastday) > time())
$lastday = date('Y-m-d',strtotime('yesterday'));
if (Minion_CLI::options('verbose')) {
echo " - From Date: ".$servicedate."\n";
echo " - To Date: ".$lastday."\n";
}
$html = new simple_html_dom();
$notdebug = TRUE;
if ($notdebug) {
if (! $debug) {
$request = Request::factory($this->aso->stats_url.'usage_customize_query.php')
->method('POST')
->post('year_search_key',date('Y',strtotime($servicedate)))
@@ -94,22 +109,31 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
$result = $response->body();
$html->load($result);
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->plugin()->service_number,$servicedate)); die();
if (Minion_CLI::options('verbose'))
$html->save(sprintf('/tmp/osb.usage.%s.%s.html',$so->plugin()->service_number,$servicedate));
} else {
$html->load_file(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->plugin()->service_number,$servicedate));
if (Minion_CLI::options('verbose'))
echo " ! From Debug File: \n";
$html->load_file(sprintf('/tmp/osb.usage.%s.%s.html',$so->plugin()->service_number,$servicedate));
}
$header = array();
$data = array();
foreach ($html->find('fieldset') as $index => $fieldset) {
if (! preg_match('/^Usage Detail/',$fieldset->find('legend',0)->plaintext))
if (! preg_match('/Usage Detail/',$fieldset->find('legend',0)->plaintext))
continue;
#echo "X:";print_r($fieldset->find('table',0)->find('tr')->plaintext); echo "\n";
#if (Minion_CLI::options('verbose'))
# echo "X:";print_r((string)$fieldset->find('table',0)); echo "\n";
foreach ($fieldset->find('table',0)->find('tr') as $key => $values) {
foreach ($values->children() as $a => $b) {
#print_r(array('a'=>$a,'b'=>$b));
#if (Minion_CLI::options('verbose'))
# print_r(array('a'=>(string)$a,'b'=>(string)$b));
# Header
if ($key == 0) {
@@ -129,7 +153,7 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
continue;
}
#echo "INDEX: $key:$a\n";
#echo "TAG: ".$b->tag."\n";
#echo "TAG: ".$b->tag."\n";d
#echo "HEADER: ".$b->plaintext."\n";
# Data
@@ -141,7 +165,9 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
#echo "VALUES: ".$b->plaintext."\n";
}
}
#print_r($data);
#if (Minion_CLI::options('verbose'))
# print_r($data);
if (isset($data['date']) && preg_match('/^[0-9]{4}/',$data['date'])) {
$sdate = date('Y-m-d',strtotime($data['date']));
@@ -158,11 +184,18 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
}
}
}
#if (Minion_CLI::options('verbose'))
# print_r($update);
}
// If we got here and have data, we had a good fetch, update the stats date
$so->plugin()->service_stats_lastupdate = $lastday;
$so->plugin()->save();
$x = $so->plugin();
$x->service_stats_lastupdate = $lastday;
$x->save();
if (Minion_CLI::options('verbose'))
printf(" = Update Service %s to %s\n",$so->plugin()->service_number,$so->plugin()->service_stats_lastupdate);
}
}