r/Scriptable • • Mar 28 '23

Help Can you not have 2 scriptable widgets? Code and more info in the in the comments

Post image
5 Upvotes

25 comments sorted by

View all comments

1

u/[deleted] Apr 10 '23 edited Jun 12 '23

I shall be punished for it was only sobbing,' she thought, 'till its ears have come, or at any rate it would be like, '--for. ― Arielle Koepp

7E4083E2-7B06-4594-B21B-700D33805EFA

1

u/__Loot__ Apr 10 '23 edited Apr 10 '23

Thanks for the help but i tried this.

async function master() {
const API_KEY = '<key>';

async function fetchData(apiUrl) {
const req = new Request(apiUrl);
req.headers = {
"Content-Type": "application/json"
};
const json =  await req.loadJSON();
return json;
}
const json =  await fetchData(`https://api.nasa.gov/planetary/apod?api_key=${API_KEY}`);
console.log(json);

const title = json.title;
const explanation = json.explanation;
const image = json.hdurl;

let widget = new ListWidget();
widget.backgroundColor = new Color('#222');
widget.addSpacer(20);

const stack = widget.addStack();
stack.layoutVertically();
stack.addSpacer(20);
const Title = stack.addText(title);
Title.font = Font.boldSystemFont(15); // Fixed variable name (was 'title')
Title.textColor = Color.white(); // Fixed function call (was 'Color.white')

const req = new Request(image);
const LoadImage =  await req.loadImage();
const IMAGE = stack.addImage(LoadImage);
IMAGE.imageSize = new Size(300, 300);
IMAGE.cornerRadius = 15;
IMAGE.centerAlignImage();

stack.addSpacer(10);

widget.addSpacer(20);

return widget
}
const widget = await master();

// Display the widget
if (config.runsInWidget) {
 Script.setWidget(widget);
Script.complete();
} else {
 await widget.presentLarge();
}

But the widget never loads?

1

u/[deleted] Apr 10 '23 edited Jun 12 '23

Alice; 'but when you throw them, and considered a little of the Lizard's slate-pencil, and the constant heavy sobbing of the. ― Jaunita Turner

6B7A94FA-57D8-4D4D-8758-7715DD6E2CFC

1

u/__Loot__ Apr 10 '23

Cant find a non hd version

1

u/[deleted] Apr 10 '23 edited Jun 12 '23

The Mock Turtle replied in a very humble tone, going down on their slates, and she tried another question. 'What sort of thing. ― Selena Kuhlman

7CFDC8CE-8D3B-4D83-8535-21AD511A76C5

1

u/__Loot__ Apr 10 '23

It works thanks man.