NEWS
Daten für Vielflieger sammeln
-
Hallo Leute,
ich würde gerne aus meinem Kalender eine Stadt auslesen und daraus, für den Tag, eine 3 Tage Voraussage anzeigen.
Bsp.: im Kalender steht am 01.01.2024 "Flug Rio de Janeiro", dann hätte ich gerne das Wetter für den 01., 02. und 03. .... Aus dem Kalender habe ich schon die Stadt gefiltert. Jetzt bräuchte ich die Wetterdaten dazu.
Hat jemand eine Idee?
-
@ldittmar sagte in 3 Tage Wettervoraussage für verschiedene Städte:
und daraus, für den Tag, eine 3 Tage Voraussage anzeigen.
@ldittmar sagte in 3 Tage Wettervoraussage für verschiedene Städte:
das Wetter für den 01., 02. und 03. ....
das wäre aber eine Vorhersage für 4 Wochen.
Da wirst du wenn überhaupt nur sehr unzuverlässige Daten bekommen -
@homoran Nee... ich will einfach an Tag des Fluges bzw ein Tag vorher sehen wir das Wetter Vorort ausehen wird. Es geht um eine Anaicht für Flugbegleiter/Piloten.
-
@ldittmar sagte in 3 Tage Wettervoraussage für verschiedene Städte:
ein Tag vorher
das müsste gehen
hast du Zugriff auf eine Wetter API?
Anbieten wird das wohl jede
-
@homoran Cool... ich habe eine neu API gefunden. Die bieten ein Query Builder an... Ok.... dann hätte ich die Daten und muss jetzt nur noch basteln
-
Ich habe jetzt ein Skript geschrieben, um alle mögliche Daten eines Reiseziels anzeigen zu können. Vielleicht braucht das noch irgendjemand...
//Settings const iCalID = 'ical.5.data.table'; //ID des Terminkalenders im ical Adapter const flightTerm = 'Flug '; //wie heißen die Termine Bsp: Flug New York - Termin als Ganztagstermin über den gesamten Aufenthalt const apiKey = 'xxxxxxxx'; // API Key für weather.visualcrossing.com const weatherIcons = '0_userdata.0/Wetter_Icons' //Link zu den Wetter-Icons - hier gibt es die Sets zum runterladen https://github.com/visualcrossing/WeatherIcons //Create Objects createState("0_userdata.0.Flug.imageURL", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.start",'', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.end",'', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.html", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.city", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.timezone", '', {type: 'string', read: true, write: false}); createState(`0_userdata.0.Flug.cityPopulation`, 0, {type: 'number', read: true, write: false}); createState("0_userdata.0.Flug.country", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.countryFullname", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.countryPopulation", 0, {type: 'number', read: true, write: false}); createState("0_userdata.0.Flug.countryArea", 0, {type: 'number', read: true, write: false, unit: 'm²'}); createState("0_userdata.0.Flug.capital", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.subregion", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.flagURL", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.coatOfArmsURL", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.language", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.drivingSide", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.currencyCode", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.currencyName", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.currencySymbol", '', {type: 'string', read: true, write: false}); createState("0_userdata.0.Flug.currencyEuro", 0, {type: 'number', read: true, write: false}); for (let i = 0; i < 7; i++) { createState(`0_userdata.0.Flug.day${i}.tempmax`, 0, {type: 'number', read: true, write: false, unit: '°C'}); createState(`0_userdata.0.Flug.day${i}.tempmin`, 0, {type: 'number', read: true, write: false, unit: '°C'}); createState(`0_userdata.0.Flug.day${i}.humidity`, 0, {type: 'number', read: true, write: false, unit: '%'}); createState(`0_userdata.0.Flug.day${i}.precipprob`, 0, {type: 'number', read: true, write: false, unit: '%'}); createState(`0_userdata.0.Flug.day${i}.snow`, 0, {type: 'number', read: true, write: false, unit: '%'}); createState(`0_userdata.0.Flug.day${i}.cloudcover`, 0, {type: 'number', read: true, write: false, unit: '%'}); createState(`0_userdata.0.Flug.day${i}.uvindex`, 0, {type: 'number', read: true, write: false}); createState(`0_userdata.0.Flug.day${i}.sunrise`, '', {type: 'string', read: true, write: false}); createState(`0_userdata.0.Flug.day${i}.sunset`, '', {type: 'string', read: true, write: false}); createState(`0_userdata.0.Flug.day${i}.icon`, '', {type: 'string', read: true, write: false}); // createState(`0_userdata.0.Flug.day${i}.date`, '', {type: 'string', read: true, write: false}); } const axios = require('axios'); on({id: iCalID, change: "any"}, async function (obj) { const events = obj.state ? obj.state.val : {}; let flightFound = false; let city = ""; let start = ""; let end = ""; let startDE = ""; let endDE = ""; events.forEach(entry => { if (entry.event.includes(flightTerm) && !flightFound) { city = entry.event.replace(/[^a-zA-Z\s-]/g, "").replace("Flug", "").trim().replace(" ", "%20"); start = formatDate(entry._object.start, "YYYY-MM-DD"); end = formatDate(entry._object.end, "YYYY-MM-DD"); flightFound = true; startDE = formatDate(entry._object.start, "DD.MM.YYYY"); endDE = formatDate(entry._object.end, "DD.MM.YYYY"); setState("0_userdata.0.Flug.start",startDE, true); setState("0_userdata.0.Flug.end",endDE, true); } }); if(flightFound){ setState("0_userdata.0.Flug.imageURL", "", true); let imageURL = ''; let country = ''; let link = "https://api.teleport.org/api/cities/?search=" + city; let firstTR = '<tr><td>'; let population = ''; let timeScript = ''; await axios.get(link).then(response => { const result = response.data; link = result["_embedded"]["city:search-results"][0]["_links"]["city:item"]["href"]; }).catch(e => {console.error("City Suche");}) await axios.get(link).then(response => { const result = response.data; population = result["population"]; setState("0_userdata.0.Flug.cityPopulation", population, true); const timezone = result["_links"]['city:timezone']['name']; setState('0_userdata.0.Flug.timezone', timezone, true); timeScript = `<script>function uhrzeit() {document.getElementById('cityTimeSpan').innerHTML = new Date().toLocaleTimeString("de-DE", {timeZone: '${timezone}'});} setInterval(uhrzeit, 900);</script>`; country = result["_links"]["city:country"]["name"]; link = result["_links"]["city:urban_area"]["href"] + "images/"; }).catch(e => {console.error("Country Search");}) await axios.get(link).then(response => { const result = response.data; imageURL = result["photos"][0]["image"]["web"]; setState("0_userdata.0.Flug.imageURL", imageURL, true); }).catch(e => {console.error("Urban Area");}) let currencyCode = ''; let currencySymbol = ''; if(country !== '') { if(country === 'United States') country = "USA"; link = `https://restcountries.com/v3.1/name/${country.replace(" ", "%20")}`; await axios.get(link).then(response => { const result = response.data[0]; setState('0_userdata.0.Flug.capital', result['capital'][0], true); setState("0_userdata.0.Flug.country", result['translations']['deu']['common'], true); setState("0_userdata.0.Flug.countryFullname", result['translations']['deu']['official'], true); setState("0_userdata.0.Flug.countryPopulation", result['population'], true); setState("0_userdata.0.Flug.countryArea", result['area'], true); setState("0_userdata.0.Flug.flagURL", result['flags']['png'], true); setState("0_userdata.0.Flug.coatOfArmsURL", result['coatOfArms']['png'], true); const language = Object.values(result['languages']).join(', '); setState("0_userdata.0.Flug.language", language, true); setState("0_userdata.0.Flug.drivingSide", result['car']['side'], true); setState("0_userdata.0.Flug.subregion", result['subregion'], true); currencyCode = Object.keys(result['currencies'])[0]; setState("0_userdata.0.Flug.currencyCode", currencyCode, true); setState("0_userdata.0.Flug.currencyName", result['currencies'][currencyCode]['name'], true); currencySymbol = result['currencies'][currencyCode]['symbol']; setState("0_userdata.0.Flug.currencySymbol", currencySymbol, true); firstTR += `<img src='${result['flags']['png']}' alt='flag' style='max-width: 50px; height: auto; float: left; margin-right: 10px;'>`; firstTR += `<img src='${result['coatOfArms']['png']}' alt='coatOfArms' style='max-width: 50px; height: auto; float: right; margin-right: 10px;'>`; firstTR += "<div style='text-align: center;'>"; firstTR += `<p><b>Land:</b> ${result['translations']['deu']['official']} <b>Region:</b> ${result['subregion']}</p>`; firstTR += `<p><b>Fläche:</b> ${result['area']} m² <b>Hauptstadt:</b> ${result['capital'][0]}</p>`; firstTR += `<p><b>Einwohner Land:</b> ${result['population']} <b>Einwohner Stadt:</b> ${population}</p>`; firstTR += `<p><b>Sprache:</b> ${language}</p>`; firstTR += `<p><b>Währung:</b> ${result['currencies'][currencyCode]['name']} <b>Fahrspur:</b> ${result['car']['side'] === 'left'?'links':'rechts'}</p>`; }).catch(e => { console.error("Country Data"); }) } if(currencyCode !== '') { link = `https://economia.awesomeapi.com.br/json/last/EUR-${currencyCode}`; log(link); await axios.get(link).then(response => { const result = response.data; log(result); const value = result[Object.keys(result)[0]].bid; setState("0_userdata.0.Flug.currencyEuro", value, true); firstTR += `<p><b>1€ entsprechen:</b> ${value} ${currencySymbol}</p>`; }).catch(e => { console.error("Currency"); }) } firstTR += "</div></td></tr>"; setState("0_userdata.0.Flug.html", "", true); let html = timeScript + "<div style='max-width: 600px; margin: 0 auto;'>"; link = `https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/${city}/${start}/${end}?unitGroup=metric&include=days%2Calerts%2Cevents&key=${apiKey}&contentType=json`; await axios.get(link).then(response => { const result = response.data; city = result.resolvedAddress; setState("0_userdata.0.Flug.city", city, true); html += `<h1 style='text-align: center;'><img style='max-width: 100%; height: auto;' src='${imageURL}' alt='Stadtbild'><span>✈ <span>${city} ${startDE} - ${endDE}</span> ✈</span></h1>`; html += "<table border='1' style='width: 100%; border-collapse: collapse;'>"; html += firstTR; html += "<tr><td><h1 style='text-align: center; padding-top:15px;' id='cityTimeSpan'/></td></tr>"; for (let i = 0; i < 7; i++) { const day = result.days[i] || {}; setState(`0_userdata.0.Flug.day${i}.tempmax`, day.tempmax || 0, true); setState(`0_userdata.0.Flug.day${i}.tempmin`, day.tempmin || 0, true); setState(`0_userdata.0.Flug.day${i}.humidity`, day.humidity || 0, true); setState(`0_userdata.0.Flug.day${i}.precipprob`, day.precipprob || 0, true); setState(`0_userdata.0.Flug.day${i}.snow`, day.snow || 0, true); setState(`0_userdata.0.Flug.day${i}.cloudcover`, day.cloudcover || 0, true); setState(`0_userdata.0.Flug.day${i}.uvindex`, day.uvindex || 0, true); setState(`0_userdata.0.Flug.day${i}.sunrise`, day.sunrise || '', true); setState(`0_userdata.0.Flug.day${i}.sunset`, day.sunset || '', true); setState(`0_userdata.0.Flug.day${i}.icon`, day.icon || '', true); setState(`0_userdata.0.Flug.day${i}.date`, formatDate(day.datetime, "DD.MM.YYYY") || '', true); if(day.icon){ html += "<tr><td>"; html += `<img src='./../${weatherIcons}/${day.icon}.png' alt='icon' style='max-width: 50px; height: auto; float: left; margin-right: 10px;'>`; html += "<div style='text-align: center;'>"; html += `<p style='font-weight: bold; margin-bottom: 5px; text-align: right;'>${formatDate(day.datetime, "DD.MM.YYYY")}</p>`; html += "<br/>"; html += `<p><b>Temperatur:</b> ${day.tempmin} - ${day.tempmax} °C <b>Luftfeuchtigkeit:</b> ${day.humidity} %</p>`; html += `<p><b>Regen:</b> ${day.precipprob} % <b>Schnee:</b> ${day.snow} %</p>`; html += `<p><b>Wolkenabdeckung:</b> ${day.cloudcover} % <b>UV-Index:</b> ${day.uvindex}</p>`; html += `<p><b>Sonnenaufgang:</b> ${day.sunrise} <b>Sonnenuntergang:</b> ${day.sunset}</p>`; html += "</div>"; html += "</td></tr>"; } } html += "</table>"; setState("0_userdata.0.Flug.html", html, true); }).catch(e => {console.error("Wetterdaten");}) }else{ setState('0_userdata.0.Flug.start','', true); setState('0_userdata.0.Flug.end','', true); setState('0_userdata.0.Flug.html', '', true); setState('0_userdata.0.Flug.imageURL', '', true); setState('0_userdata.0.Flug.coatOfArmsURL', '', true); setState('0_userdata.0.Flug.city', '', true); setState('0_userdata.0.Flug.timezone', '', true); setState('0_userdata.0.Flug.cityPopulation', 0, true); setState('0_userdata.0.Flug.country', '', true); setState('0_userdata.0.Flug.countryPopulation', 0, true); setState('0_userdata.0.Flug.countryArea', 0, true); setState('0_userdata.0.Flug.countryFullname', '', true); setState('0_userdata.0.Flug.capital', '', true); setState('0_userdata.0.Flug.countryPopulation', 0, true); setState('0_userdata.0.Flug.flagURL', '', true); setState('0_userdata.0.Flug.currencyCode', '', true); setState('0_userdata.0.Flug.currencySymbol', '', true); setState('0_userdata.0.Flug.currencyName', '', true); setState('0_userdata.0.Flug.currencyEuro', 0, true); setState('0_userdata.0.Flug.language', '', true); setState('0_userdata.0.Flug.drivingSide', '', true); for (let i = 0; i < 7; i++) { setState(`0_userdata.0.Flug.day${i}.tempmax`, 0, true); setState(`0_userdata.0.Flug.day${i}.tempmin`, 0, true); setState(`0_userdata.0.Flug.day${i}.humidity`, 0, true); setState(`0_userdata.0.Flug.day${i}.precipprob`, 0, true); setState(`0_userdata.0.Flug.day${i}.snow`, 0, true); setState(`0_userdata.0.Flug.day${i}.cloudcover`, 0, true); setState(`0_userdata.0.Flug.day${i}.uvindex`, 0, true); setState(`0_userdata.0.Flug.day${i}.sunrise`, '', true); setState(`0_userdata.0.Flug.day${i}.sunset`, '', true); setState(`0_userdata.0.Flug.day${i}.icon`, '', true); setState(`0_userdata.0.Flug.day${i}.date`, '', true); } } });
Die Daten sehen dann so aus...
Als Adapter braucht man den iCal und man muss im Javascript axios als dep hinzufügen.