Skip to content

Instantly share code, notes, and snippets.

@dcatanzaro
Last active November 12, 2021 14:42
Show Gist options
  • Save dcatanzaro/8833df28c485733f1723a817acbe265d to your computer and use it in GitHub Desktop.
Save dcatanzaro/8833df28c485733f1723a817acbe265d to your computer and use it in GitHub Desktop.
Pokemon del día
const numberDay = () => {
const now = new Date();
const start = new Date(now.getFullYear(), 0, 0);
const diff = now - start;
const oneDay = 1000 * 60 * 60 * 24;
const day = Math.floor(diff / oneDay);
return day;
};
const pokemonUrl = `https://pokeapi.co/api/v2/pokemon/${numberDay()}`;
const req = new Request(pokemonUrl);
const res = await req.loadJSON();
if (config.runsInWidget) {
const widget = new ListWidget();
const imgReqBq = await new Request("https://i.pinimg.com/originals/aa/34/e1/aa34e1c76a6569a36499ae86098759ee.jpg");
const imgBq = await imgReqBq.loadImage();
widget.backgroundImage = imgBq;
const title = widget.addText("Pokemon del día");
title.textColor = Color.black();
title.textOpacity = 0.8;
title.font = new Font("Courier", 16);
widget.addSpacer(5);
const namePokemon = widget.addText(`#${res.id} - ${res.name}`);
namePokemon.textColor = Color.black();
namePokemon.textOpacity = 0.8;
namePokemon.font = new Font("Courier", 14);
const imgReq = await new Request(res.sprites.front_default);
const img = await imgReq.loadImage();
const image = widget.addImage(img);
image.centerAlignImage();
Script.setWidget(widget);
Script.complete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment