Created
September 21, 2016 10:29
-
-
Save KarlBaumann/13397ff987e6ef649b62cb8e6c83578e to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<!-- | |
To change this license header, choose License Headers in Project Properties. | |
To change this template file, choose Tools | Templates | |
and open the template in the editor. | |
--> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<?php | |
$dateFrom = "2016-09-10"; | |
$dateTo = date("Y-m-d H:i"); | |
$columns = 'sourceID; utcTimeStamp; locTimeStamp; value'; | |
$host = 'utilitytool.casc.eu'; | |
$baseURL = '/CascUtilityWebService.asmx/GetLTNForAPeriod'; | |
$fileName = "casc_LTN_".$dateFrom."s.csv"; | |
$result = downloaderFromCASC($host, $baseURL, $dateFrom, $dateTo); | |
$valueList = readXML($result, $columns); | |
writeToCSV($valueList, $fileName); | |
function downloaderFromCASC($host, $baseURL, $dateFrom, $dateTo){ | |
if($curl = curl_init()) { | |
curl_setopt($curl, CURLOPT_URL, $host.$baseURL); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, "dateFrom=".$dateFrom."&dateTo=".$dateTo); | |
$out = curl_exec($curl); | |
curl_close($curl); | |
return $out; | |
} | |
} | |
function readXML($result, $columns){ | |
$valueList = simplexml_load_string($result); | |
$row =""; | |
foreach ($valueList as $value) | |
{ | |
$row .= "1; ".date_create($value->Date)->Format("d.m.Y H:i"). ";".date("d.m.Y H:i")."; ". $value->BEFR."\n"; | |
$row .= "2; ".date_create($value->Date)->Format("d.m.Y H:i").";".date("d.m.Y H:i")."; ".$value->BENL."\n"; | |
$row .= "3; ".date_create($value->Date)->Format("d.m.Y H:i").";".date("d.m.Y H:i")."; ".$value->DEATFR."\n"; | |
$row .= "4; ".date_create($value->Date)->Format("d.m.Y H:i").";".date("d.m.Y H:i")."; ".$value->DEATNL."\n"; | |
$row .= "5; ".date_create($value->Date)->Format("d.m.Y H:i").";".date("d.m.Y H:i")."; ".$value->FRBE."\n"; | |
$row .= "6; ".date_create($value->Date)->Format("d.m.Y H:i").";".date("d.m.Y H:i")."; ".$value->FRDEAT."\n"; | |
$row .= "7; ".date_create($value->Date)->Format("d.m.Y H:i").";".date("d.m.Y H:i")."; ".$value->NLBE."\n"; | |
$row .= "8; ".date_create($value->Date)->Format("d.m.Y H:i").";".date("d.m.Y H:i")."; ".$value->NLDEAT."\n"; | |
} | |
return $valueList = $columns."\n".$row; | |
} | |
function writeToCSV($valueList, $fileName){ | |
$file = fopen($fileName, 'w'); | |
fwrite($file, $valueList); | |
fclose($file); | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment