import { fetch } from "https://esm.town/v/std/fetch";
import { dataToRSS } from "https://esm.town/v/Glench/dataToRSS";
import process from "node:process";
export const tvshows = async function (req, res: express.Response) {
const TV_SHOWS_WATCHED = [
97546,
95215,
14658,
87012,
80475,
83631,
134581,
84773,
76075,
];
const data = [];
for (var i = 0; i < TV_SHOWS_WATCHED.length; ++i) {
const show_id = TV_SHOWS_WATCHED[i];
const url =
`https://api.themoviedb.org/3/tv/${show_id}?api_key=${process.env.tmdb_api_key}`;
const resp = await fetch(url);
const show = await resp.json();
data.push(show);
}
data.sort(function (a, b) {
if (a.last_air_date > b.last_air_date)
return -1;
if (a.last_air_date < b.last_air_date)
return 1;
return 0;
});
res.send(dataToRSS(data, {
title: "My TV Shows",
link: "https://www.val.town/Glench.tvshows",
description: "Personal shows from tmdb api and val.town",
item: {
title: (x) =>
`${x.name} - ${x.last_episode_to_air.name} (${x.last_episode_to_air.season_number}x${x.last_episode_to_air.episode_number})`,
link: (x) => x.last_episode_to_air.id,
description: (x) => x.last_episode_to_air.overview,
pubDate: (x) => x.last_episode_to_air.air_date,
},
}));
};