-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
113 lines (77 loc) · 2.96 KB
/
index.php
File metadata and controls
113 lines (77 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
require __DIR__ . '/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/client_secret.json');
$client = new Google_Client;
$client->useApplicationDefaultCredentials();
$client->setApplicationName("Something to do with my representatives");
$client->setScopes(['https://www.googleapis.com/auth/drive','https://spreadsheets.google.com/feeds']);
if ($client->isAccessTokenExpired()) {
$client->refreshTokenWithAssertion();
}
$accessToken = $client->fetchAccessTokenWithAssertion()["access_token"];
ServiceRequestFactory::setInstance(
new DefaultServiceRequest($accessToken)
);
// Get our spreadsheet
$spreadsheet = (new Google\Spreadsheet\SpreadsheetService)
->getSpreadsheetFeed()
->getByTitle('WSDOT');
// Get the first worksheet (tab)
$worksheets = $spreadsheet->getWorksheetFeed()->getEntries();
$worksheet = $worksheets[0];
use HtmlDom\HtmlDomParser;
/**
* Created by PhpStorm.
*/
include_once ('libs/HttpHandler.php');
include_once ('libs/StringParser.php');
include_once ('HtmlDomParser/HtmlDomParser.php');
$httpHandler = new HttpHandler();
$link = "";
$source = $httpHandler->http_get($link, '');
$data = $source['FILE'];
$data = preg_replace('/new Date\(\d*\)/m', '""', $data);
$data = json_decode($data);
foreach($data->FeedContentList as $list){
if($list->Terminal->TerminalID == 3){
echo $list->Terminal->TerminalName."\n"; // Departure Terminal
foreach($list->DepartSailingSpaces as $terminal){
echo $terminal->Departure."\n"; // Departure Time
echo $terminal->ArriveSailingSpaces[0]->TerminalName."\n"; // Destination Terminal
echo $terminal->Vessel."\n";
echo $terminal->ArriveSailingSpaces[0]->DriveUpInfo."\n";
// echo $terminal->ArriveSailingSpaces[0]->MaxSpaceCount."\n";
$listFeed = $worksheet->getListFeed();
$listFeed->insert([
'terminal' => $list->Terminal->TerminalName,
'time' => $terminal->Departure,
'destination' => $terminal->ArriveSailingSpaces[0]->TerminalName,
'spaces' => $terminal->ArriveSailingSpaces[0]->DriveUpInfo,
'vessel' => $terminal->Vessel,
'captured' => date('d-m-Y h:i')
]);
}
}
echo "\n";
}
// $listFeed = $worksheet->getListFeed();
// /** @var ListEntry */
// foreach ($listFeed->getEntries() as $entry) {
// $representative = $entry->getValues();
// foreach($representative as $value){
// echo $value . "\n";
// }
// }
/* Deleting previous data */
// $listFeed = $worksheet->getListFeed();
// foreach ($listFeed->getEntries() as $entry) {
// $entry->delete();
// for($i=0; $i<1; $i++){
// //$entry->delete();
// }
// }
// echo "Data Delete Successfull\n";
/* Inserting data */
echo "Data Insert Successfull\n";