-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.html
188 lines (158 loc) · 6.76 KB
/
scraper.html
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ZHU VATSIM Scrapper</title>
<style>
body {
font-family: 'Open Sans', sans-serif;
line-height: 1.75em;
background-color: #222;
color: #fff;
}
thead {
background-color: #af2512;
color: white;
text-align: left;
text-transform: uppercase;
}
thead th {
border: 1px solid #18181b;
padding: 5px;
cursor: pointer;
}
tbody td {
padding: 5px;
border: 1px solid #18181b;
vertical-align: top;
}
tbody tr:nth-child(odd) {
background-color: #333;
}
tbody tr:nth-child(even) {
background-color: #666;
}
.highlight-departure {
background-color: darkgreen;
color: white;
}
.highlight-arrival {
background-color: darkred;
color: white;
}
button {
font-family: 'Open Sans', sans-serif;
font-weight: bold;
background-color: #b88728;
color: white;
padding: 10px;
margin-right: 5px;
width: 150px;
border: 0px;
border-radius: 20px;
}
.lightblue {
background-color: #1e8ad6;
}
</style>
</head>
<body>
<h1>ZHU VATSIM Flight Scrapper</h1>
<p>Refresh the page to update flights. Click on a column to sort.</p>
<table id="aircraftTable">
<thead>
<tr>
<th onclick="sortTable(0)">Callsign</th>
<th onclick="sortTable(1)">Rules</th>
<th onclick="sortTable(2)">Equip</th>
<th onclick="sortTable(3)">DEP</th>
<th onclick="sortTable(4)">ARR</th>
<th onclick="sortTable(5)">Cruise</th>
<th onclick="sortTable(6)">Alt</th>
<th onclick="sortTable(7)">Route</th>
<th onclick="sortTable(8)">Remarks</th>
</tr>
</thead>
<tbody>
<!-- Table rows will be populated here -->
</tbody>
</table>
<script>
const airportCodes = ["KAEX", "KARA", "KAUS", "KBAZ", "KBFM", "KBIX", "KBPT", "KBRO", "KBTR", "KCLL", "KCRP", "KCWF", "KCXO", "KDLF", "KDWH", "KEDC", "KEFD", "KGLS", "KGPT", "KGTU", "KHDC", "KHOU", "KHRL", "KHSA", "KHUM", "KHYI", "KIAH", "KLCH", "KLFT", "KLRD", "KMFE", "KMOB", "KMSY", "KNBG", "KNEW", "KNGP", "KNGW", "KNOG", "KNQI", "KNWL", "KPOE", "KPQL", "KRND", "KSAT", "KSGR", "KSKF", "KSSF", "KTME", "KVCT"];
const url = "https://data.vatsim.net/v3/vatsim-data.json";
let sortDirection = true; // true for ascending, false for descending
async function fetchData() {
try {
const response = await fetch(url);
const data = await response.json();
const aircraftList = data.pilots || [];
// Filter aircraft based on departure or arrival matching the airport codes
const filteredAircraft = aircraftList.filter(aircraft => {
const flightPlan = aircraft.flight_plan;
return flightPlan && (
airportCodes.includes(flightPlan.departure) ||
airportCodes.includes(flightPlan.arrival)
);
});
// Populate the HTML table with filtered data
populateTable(filteredAircraft);
// Initial sort by Callsign (column index 0) in ascending order
sortTable(0, true);
} catch (error) {
console.error("Error fetching data:", error);
}
}
function populateTable(aircraftData) {
const tableBody = document.getElementById("aircraftTable").getElementsByTagName("tbody")[0];
tableBody.innerHTML = ""; // Clear existing table rows
aircraftData.forEach(aircraft => {
const flightPlan = aircraft.flight_plan || {};
const row = tableBody.insertRow();
// Create cells and apply highlighting to DEP and ARR columns if applicable
row.insertCell().textContent = aircraft.callsign || "";
row.insertCell().textContent = flightPlan.flight_rules || "";
row.insertCell().textContent = flightPlan.aircraft_faa || "";
const depCell = row.insertCell();
depCell.textContent = flightPlan.departure || "";
if (airportCodes.includes(flightPlan.departure)) {
depCell.classList.add("highlight-departure");
}
const arrCell = row.insertCell();
arrCell.textContent = flightPlan.arrival || "";
if (airportCodes.includes(flightPlan.arrival)) {
arrCell.classList.add("highlight-arrival");
}
row.insertCell().textContent = flightPlan.cruise_tas || "";
row.insertCell().textContent = flightPlan.altitude || "";
row.insertCell().textContent = flightPlan.route || "";
row.insertCell().textContent = flightPlan.remarks || "";
});
}
function sortTable(columnIndex, initialSort = false) {
const tableBody = document.getElementById("aircraftTable").getElementsByTagName("tbody")[0];
const rows = Array.from(tableBody.rows);
rows.sort((a, b) => {
const cellA = a.cells[columnIndex].textContent.toLowerCase();
const cellB = b.cells[columnIndex].textContent.toLowerCase();
if (cellA < cellB) {
return (sortDirection || initialSort) ? -1 : 1;
}
if (cellA > cellB) {
return (sortDirection || initialSort) ? 1 : -1;
}
return 0;
});
// Toggle sort direction for next click unless it's the initial sort
if (!initialSort) {
sortDirection = !sortDirection;
}
// Reorder table rows based on the sorted rows
rows.forEach(row => tableBody.appendChild(row));
}
// Initial fetch to populate the table on page load
fetchData();
</script>
</body>
</html>