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
import { fetch } from "https://esm.town/v/std/fetch";
export const checkRyanair = (async () => {
// Plan:
// 1. Make this function return Ryanair flights with desired prices according to params
// 2. Unhardcode params
// 3. Add email notification if found
// 4. Clean up code, error handling, etc
// 5. Configure, start cron and wait
//
// Currently only returns 1 flight..
// possible v4 endpoint here:
// https://www.ryanair.com/api/farfnd/v4/roundTripFares?departureAirportIataCode=STN&outboundDepartureDateFrom=2023-11-01&market=en-gb&adultPaxCount=1&arrivalAirportIataCode=RBA&searchMode=ALL&outboundDepartureDateTo=2023-11-30&inboundDepartureDateFrom=2
// possibly more info in this gist: https://gist.github.com/vool/bbd64eeee313d27a82ab
//
const BASE_URL = "https://services-api.ryanair.com/farfnd/3/";
const AIRPORT_FROM = "VNO";
const AIRPORT_TO = "MLA";
const START_FROM = "2023-08-01";
const START_TO = "2023-09-01";
const END_FROM = "2023-07-01";
const END_TO = "2023-09-30";
const PRICE_LIMIT = "260";
const fetchUrl = `${BASE_URL}roundTripFares?` +
`&arrivalAirportIataCode=${AIRPORT_TO}` +
`&departureAirportIataCode=${AIRPORT_FROM}` +
`&outboundDepartureDateFrom=${START_FROM}` +
`&outboundDepartureDateTo=${START_TO}` +
`&inboundDepartureDateFrom=${END_FROM}` +
`&inboundDepartureDateTo=${END_TO}` +
`&priceValueTo=${PRICE_LIMIT}`;
const res = await fetch(fetchUrl);
const flights = await res.json();
console.log(flights?.total);
if (flights?.total > 0) {
console.log(flights.fares[0].outbound.departureDate);
console.log(flights.fares[0].inbound.departureDate);
}
console.log(flights);
})();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023