import { fetch } from "https://esm.town/v/std/fetch";
import { email } from "https://esm.town/v/std/email?v=9";
import process from "node:process";
export const sendFoodEmail = async () => {
const randomNumber = Math.floor(Math.random() * 80);
let recipeName = "";
let recipeDescription = "";
let pictureUrl = "";
let videoLink = "";
const url =
"https://tasty.p.rapidapi.com/recipes/list?from=0&size=80&tags=under_30_minutes";
const options = {
method: "GET",
headers: {
"X-RapidAPI-Key": process.env.tastyAPIKey,
"X-RapidAPI-Host": "tasty.p.rapidapi.com",
},
};
try {
const response = await fetch(url, options);
const result = await response.json();
recipeName = result.results[randomNumber].name;
recipeDescription = result.results[randomNumber].description;
pictureUrl = result.results[randomNumber].thumbnail_url;
videoLink = result.results[randomNumber].original_video_url;
}
catch (error) {
console.error(error);
}
let subject = `My daily (fast and yummy) recipe`;
let html = `<h1>${recipeName}</h1>
<p>Heute habe ich folgende Idee:</p>
<p>${recipeDescription}</p>
<img src=${pictureUrl} />
<a href=${videoLink} target="_blank">Video</a>
<p>Dazu ein Glas Chardonnay!
</p>`;
await email({ html, subject });
};