Skip to content

Instantly share code, notes, and snippets.

@johannschopplich
Created September 5, 2023 07:20
Show Gist options
  • Save johannschopplich/f68744106d8247a188231c2fd8d11d10 to your computer and use it in GitHub Desktop.
Save johannschopplich/f68744106d8247a188231c2fd8d11d10 to your computer and use it in GitHub Desktop.
Check which tables are available for Seven SwansSEVEN SWANS restaurant in Frankfurt am Main
// Function to fetch reservation data from API
async function fetchReservationData(date, capacity = 2, agentId = 2) {
const baseUrl =
'https://9110-api.quandoo.com/merchants/56296/reservation-options'
const url = `${baseUrl}?date=${date}&capacity=${capacity}&agentId=${agentId}`
try {
const response = await fetch(url)
const data = await response.json()
if (data.options && data.options.length > 0) {
console.log(`Reservation options are available for ${date}.`)
} else {
console.log(`No reservation options available for ${date}.`)
}
} catch (error) {
console.error(`Error fetching data for ${date}: ${error}`)
}
}
// Function to get dates from today to end of next year
const getDatesUntilEndOfNextYear = () => {
const dates = []
const currentDate = new Date()
const endOfYear = new Date('2025-12-31')
while (currentDate <= endOfYear) {
dates.push(formatDate(currentDate))
currentDate.setDate(currentDate.getDate() + 1)
}
return dates
}
// Custom function to format date into YYYY-MM-DD
const formatDate = (date) => {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0') // Months are 0-based
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
// Main function
async function main() {
const dates = getDatesUntilEndOfNextYear()
for (const date of dates) {
await fetchReservationData(date)
}
}
// Run the main function
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment