Skip to content

Commit

Permalink
see changelog.md
Browse files Browse the repository at this point in the history
  • Loading branch information
afiqiqmal committed Sep 4, 2018
1 parent 1f2245d commit ddf5b62
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ $data = parcel_track()
<tr>
<td>ups()</td>
<td></td>
<td>United Parcel Service Courier/td>
<td>United Parcel Service Courier</td>
</tr>
<tr>
<td>setTrackingNumber($refNumber)</td>
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 1.2
- FIx LEL Express changing their URL
- Fix Skynet Because of Changing of the UI

## 1.11
Add New Courier UPS Express
- add United Parcel Service (M) Sdn Bhd (Main)
Expand Down
4 changes: 2 additions & 2 deletions example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require_once __DIR__ .'/../vendor/autoload.php';

//$response = parcel_track()->gdExpress()->setTrackingNumber("4941410530")->fetch();
//$response = parcel_track()->skynet()->setTrackingNumber("238216506684")->fetch();
$response = parcel_track()->skynet()->setTrackingNumber("238216506684")->fetch();
//$response = parcel_track()->abxExpress()->setTrackingNumber("EZP843055940197")->fetch();
//$response = parcel_track()->dhlExpress()->setTrackingNumber("5176011131")->fetch();
//$response = parcel_track()->cityLink()->setTrackingNumber("960307804711915")->fetch();
Expand All @@ -20,7 +20,7 @@
//$response = parcel_track()->lelExpress()->setTrackingNumber("MYMP000000573505")->fetch();
//$response = parcel_track()->dhlECommerce()->setTrackingNumber("5218031053514008AAAA")->fetch();
//$response = parcel_track()->ktmd()->setTrackingNumber("103154269")->fetch();
$response = parcel_track()->ups()->setTrackingNumber("1Z0V255F0498628539")->fetch();
//$response = parcel_track()->ups()->setTrackingNumber("1Z0V255F0498628539")->fetch();

//$response = parcel_track()->setTrackingNumber("EZP843055940197")->checkCourier();

Expand Down
2 changes: 1 addition & 1 deletion src/Tracker/LELExpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class LELExpress extends BaseTracker
{
protected $url = "http://www.lex.com.my/tracker/";
protected $url = "https://tracker.lel.asia/";
protected $source = "Lazada E-Logistic Express";
protected $code = "lex";

Expand Down
89 changes: 72 additions & 17 deletions src/Tracker/SkyNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,94 @@ public function startCrawl($result)
{
if (isset($result['body'])) {
$crawler = new Crawler($result['body']);
$crawlerResult = $crawler->filter('#tr2' . $this->getTrackingNumber())
->filter('table tr')->each(function (Crawler $node, $i) {
$result = $node->filter('td')->each(function (Crawler $node, $i) {
return trim_spaces($node->text());
});

return $this->removeAllNullInArray($result, true);
});

$currentDate = null;
$dataLast = [];
if (isset($crawlerResult[0][0]) && Carbon::hasFormat($crawlerResult[0][0], 'd M Y')) {
$currentDate = $crawlerResult[0][0].' '.$crawlerResult[1][1];
$parcel = Carbon::createFromFormat("d M Y g:i A", $currentDate);
$dataLast[] = [
'date' => $parcel->toDateTimeString(),
'timestamp' => $parcel->timestamp,
'process' => $crawlerResult[1][0],
'type' => $this->distinguishProcess($crawlerResult[1][0]),
'event' => ucwords(strtolower($crawlerResult[1][2])),
];
} else {
return $this->buildResponse($result, $dataLast);
}

$crawlerResult = $crawler->filter('#tr4' . $this->getTrackingNumber())
->filter('table tr')->each(function (Crawler $node, $i) {
$result = $node->filter('td')->each(function (Crawler $node, $i) {
return trim_spaces($node->text());
});
$data = [];
foreach ($result as $key => $item) {
if ($key == 0) {
$data['date'] = $item;
}
if ($key == 1) {
$data['process'] = $item;
$data['type'] = $this->distinguishProcess($item);
}

if ($key == 2) {
$parcel = Carbon::createFromFormat("d M Y h:i a", $data['date'] . " " . $item);
$data['date'] = $parcel->toDateTimeString();
$data['timestamp'] = $parcel->timestamp;
$result = $this->removeAllNullInArray($result, true);
if ($result) {
if (isset($result[1])) {
unset($result[1]);
$result = array_values($result);
}
if (Carbon::hasFormat($result[0], 'd M Y')) {
return $result;
}

if ($key == 3) {
$data['event'] = $item;
if (Carbon::hasFormat($result[0], 'g:i A')) {
return $result;
}
}

return $data;
return null;
});

return $this->buildResponse($result, $crawlerResult);
$data = $this->removeAllNullInArray($crawlerResult);
$currentDate = null;
foreach ($data as $item) {
if (isset($item[0]) && Carbon::hasFormat($item[0], 'd M Y')){
$currentDate = $item[0];
}

if (count($item) > 1) {
$parcel = Carbon::createFromFormat("d M Y g:i A", $currentDate . " " . $item[0]);
$dataLast[] = [
'date' => $parcel->toDateTimeString(),
'timestamp' => $parcel->timestamp,
'process' => $item[1],
'type' => $this->distinguishProcess($item[1]),
'event' => ucwords(strtolower($item[2])),
];
}
}

return $this->buildResponse($result, $dataLast);
}

return $this->buildResponse($result, []);
}

private function removeAllNullInArray($array, $removeDuplicate = false)
{
$newData = [];
$array = array_values(array_filter($array));
foreach ($array as $item) {
if ($item != null) {
$newData[] = $item;
}
}

if ($removeDuplicate) {
$newData = array_unique($array, SORT_REGULAR);
}

return $newData;
}
}

0 comments on commit ddf5b62

Please sign in to comment.