Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class WorldOfTrucks
- {
- private $instanceID = null;
- private $websiteURI = "https://worldoftrucks.com/en/online_profile.php?id=";
- private $websiteData = null;
- private $claimedData = null;
- public function __construct( $uid )
- {
- $this->instanceID = $uid;
- $this->websiteData = file_get_contents( $this->websiteURI.$this->instanceID );
- }
- public function fetchData()
- {
- $this->websiteData = $this->gsb( $this->websiteData , "Global statistics" , "cleaner" );
- $this->websiteData = explode("\n",$this->websiteData);
- $out = [
- $this->websiteData[2],
- $this->websiteData[9],
- $this->websiteData[16],
- $this->websiteData[23],
- $this->websiteData[30]
- ];
- foreach( $out as $row )
- {
- $temp = explode("<br>",$row);
- $output[] = [
- "ETS" => $this->gsb($temp[0],"right'>","</span>"),
- "ATS" => $this->gsb($temp[1],"right'>","</span>"),
- ];
- }
- $this->claimedData = $output;
- $this->normalizeUnits();
- }
- public function debug()
- {
- var_dump($this->claimedData);
- }
- private function normalizeUnits()
- {
- $data = [
- (int)round((explode(" ",$this->claimedData[1]["ATS"])[0]*1.016)),
- (int)round(explode(" ",$this->claimedData[3]["ATS"])[0]*1.609344),
- (int)str_replace(',','',explode(" ",$this->claimedData[4]["ETS"])[0]),
- (int)round(str_replace(',','',explode(" ",$this->claimedData[4]["ATS"])[0])*1.609344)
- ];
- $this->claimedData[1]["ATS"] = $data[0]." t";
- $this->claimedData[3]["ATS"] = $data[1]." km";
- $this->claimedData[4]["ETS"] = $data[2]." km";
- $this->claimedData[4]["ATS"] = $data[3]." km";
- }
- public function getData( $mode = "GLOBAL" )
- {
- if( $mode == "GLOBAL" )
- {
- $out = [
- "TOTAL_JOBS" => $this->claimedData[0]["ETS"]+$this->claimedData[0]["ATS"],
- "TOTAL_MASS" => explode(" ",$this->claimedData[1]["ATS"])[0]+explode(" ",$this->claimedData[1]["ETS"])[0]." t",
- "TOTAL_DISTANCE" => (explode(" ",$this->claimedData[4]["ATS"])[0])+(explode(" ",$this->claimedData[4]["ETS"])[0])." t",
- "AVERAGE_DISTANCE" => round((explode(" ",$this->claimedData[4]["ATS"])[0]+explode(" ",$this->claimedData[4]["ETS"])[0])/( $this->claimedData[0]["ETS"]+$this->claimedData[0]["ATS"]))." km",
- "TOTAL_TIME" => (explode(" ",$this->claimedData[2]["ETS"])[0] + explode(" ",$this->claimedData[2]["ATS"])[0])." h ".( explode(" ",$this->claimedData[2]["ETS"])[2] + explode(" ",$this->claimedData[2]["ATS"])[2] )." min"
- ];
- }else{
- $out = [
- "TOTAL_JOBS" => $this->claimedData[0][$mode],
- "TOTAL_MASS" => $this->claimedData[1][$mode],
- "TOTAL_DISTANCE" => $this->claimedData[4][$mode],
- "AVERAGE_DISTANCE" => $this->claimedData[3][$mode],
- "TOTAL_TIME" => $this->claimedData[2][$mode],
- ];
- }
- var_dump($out);
- }
- private function gsb( string $string , string $start , string $end )
- {
- $string = ' ' . $string;
- $ini = strpos($string, $start);
- if ($ini == 0) return '';
- $ini += strlen($start);
- $len = strpos($string, $end, $ini) - $ini;
- return substr($string, $ini, $len);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment