-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.ts
58 lines (40 loc) · 1.71 KB
/
requests.ts
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
import axios, { AxiosResponse } from 'axios';
import { Route } from './types';
const finaliseNumber = (num: number): string => {
if (num < 10) {
return '0' + num;
} else {
return num.toString();
}
}
function GetTracks() {
const d = new Date();
return axios.get(`https://menetrend.kecskemet.hu/api/api/tracks/${finaliseNumber(d.getFullYear())}${finaliseNumber(d.getMonth() + 1)}${finaliseNumber(d.getDate())}`)
}
async function GetTrack(id: string, korjarat: boolean) {
const d = new Date();
let a: Route[] = []
a.push(...(await axios.get(`https://menetrend.kecskemet.hu/api/api/routes/${finaliseNumber(d.getFullYear())}${finaliseNumber(d.getMonth() + 1)}${finaliseNumber(d.getDate())}/${id}/1`)).data)
if (!korjarat) {
a.push(...(await axios.get(`https://menetrend.kecskemet.hu/api/api/routes/${finaliseNumber(d.getFullYear())}${finaliseNumber(d.getMonth() + 1)}${finaliseNumber(d.getDate())}/${id}/2`)).data)
}
return a
}
function GetStops(id: string) {
const d = new Date();
return axios.get(`https://menetrend.kecskemet.hu/api/api/path/${finaliseNumber(d.getFullYear())}${finaliseNumber(d.getMonth() + 1)}${finaliseNumber(d.getDate())}/${id}`)
}
async function GetVehiclePosition(id: string) {
const d = new Date();
let a: AxiosResponse
let res = false;
while (res == false) {
try {
a = await axios.get(`https://menetrend.kecskemet.hu/api/api/vehicleposition/${finaliseNumber(d.getFullYear())}${finaliseNumber(d.getMonth() + 1)}${finaliseNumber(d.getDate())}/${id}`)
res = true;
} catch(e) {
}
}
return a;
}
export { GetTracks, GetTrack, GetStops, GetVehiclePosition }