diff --git a/mooncal/chat.js b/mooncal/chat.js new file mode 100644 index 0000000..5d5604d --- /dev/null +++ b/mooncal/chat.js @@ -0,0 +1,32 @@ +async function getChatGPTResponse(prompt) { + const url = `https://mooncalendar.glitch.me/api/chatgpt`; + + try { + const response = await fetch(url, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ prompt }) + }); + + if (!response.ok) { + throw new Error(`Error: ${response.statusText}`); + } + + const data = await response.json(); + console.log("ChatGPT response:", data.response); + + return data.response; // Return the chatbot's response + } catch (error) { + console.error("Failed to get response from ChatGPT:", error); + } + + return null; // Default to null if fetching fails + } + + // Example Usage + getChatGPTResponse("Tell me a joke about programming.").then(response => { + if (response) { + console.log("ChatGPT says:", response); + } + }); + \ No newline at end of file diff --git a/mooncal/index.html b/mooncal/index.html index 0ef7dd7..4b5ca01 100644 --- a/mooncal/index.html +++ b/mooncal/index.html @@ -21,6 +21,7 @@

Laden...

+ diff --git a/mooncal/moondata.js b/mooncal/moondata.js index 16a8547..14b2f8b 100644 --- a/mooncal/moondata.js +++ b/mooncal/moondata.js @@ -79,8 +79,6 @@ async function fetchMoonPhase(location, date) { return null; } - - function getMoonPhasePercentage(normalizedPhase) { return Math.round(normalizedPhase * 100); // Convert to percentage and round off } @@ -91,10 +89,9 @@ async function initialize() { const selectedDate = parseDate(queryDate); const dateForApi = formatDateForAPI(selectedDate); const location = getQueryParam('location') || 'Zurich, Switzerland'; // Default location - const apiKey = 'ABCDEFGHIJK'; // Replace with your actual API key // Fetch the moon phase from the API - const apiMoonPhase = await fetchMoonPhase(location, dateForApi, apiKey); + const apiMoonPhase = await fetchMoonPhase(location, dateForApi); if (apiMoonPhase !== null) { const moonPhaseName = getMoonPhaseName(apiMoonPhase); const moonPhaseImage = getMoonPhaseImage(apiMoonPhase);