Widget Examples

I think there was probably some problems hours ago with the API. It’s normal now for me.

If you use the script I posted earlier, there’s a spot where you can add your own code. I used @riverwolf’s greeting code for this:

// Get the current date
const date = new Date()

// Format the greeting (thank you riverwolf)
let greeting = "Good "
if (date.getHours() < 6) {
	greeting = greeting + "night."
} else if (date.getHours() < 12) {
	greeting = greeting + "morning."
} else if (date.getHours() < 17) {
	greeting = greeting + "afternoon."
} else if (date.getHours() < 21) {
	greeting = greeting + "evening."
} else {
	greeting = greeting + "night."

// Format the date
let df = new DateFormatter()
df.dateFormat = "EEEE, MMMM d"

// Format the widget

let greetingText = widget.addText(greeting)
greetingText.font = Font.boldSystemFont(36)
greetingText.textColor = Color.white()

let dateText = widget.addText(df.string(date))
dateText.font = Font.regularSystemFont(18)
dateText.textColor = Color.white()


I think it looks pretty similar:


A post was merged into an existing topic: Radio Paradise Now Playing

Hi, I realise I have been a little quiet on here and missed some replies / questions.

I am working on a couple of ideas, in the meantime I have updated my reddit widget. The standard uses the old method, the new uses stacks and has links to open the post too.

Here is a screenshot of the two side by side:

Code can be found here:



The parameter is as follows:
The client to open @ the subreddit @ placeholder - this was for debugging @ whether to show pics (this is to be coded) @ How many entries - this will depend on font sizes ‘ verbosity of posts.

1 Like

30 posts were split to a new topic: OpenWeather Forecast

Thankyou so much!!!

This looks awesome! Getting this error though:

2020-09-30 09:37:21: Error on line 103:25: ReferenceError: Can't find variable: shouldRound

Any ideas?

Hmm :thinking:, that’s strange, since the function is declared near the end of the file.

If someone got it to work, I would appreciate if you share a screenshot, I would like to see it on other devices :hugs:.

@jimmyhartington I was also confused about how to do this - here you go (purple highlights)!

@egamez Love this - thank you! how do we change the units to Fahrenheit :slightly_frowning_face:

found it! just change the units parameter to “imperial” on line 81 as follows:
weatherData = await new Request("https://api.openweathermap.org/data/2.5/onecall?lat=" + LAT + "&lon=" + LON + "&exclude=daily,minutely,alerts&units=imperial&lang=en&appid=" + API_KEY).loadJSON();

here’s how it looks like on my screen.

Looks great on iPad Pro 12.9. Nice work on this Widget!

Change units=metric to units=imperial

weatherData = await new Request("https://api.openweathermap.org/data/2.5/onecall?lat=" + LAT + "&lon=" + LON + "&exclude=daily,minutely,alerts&units=imperial&lang=en&appid=" + API_KEY).loadJSON();

1 Like

I will set this as a parameter :sweat_smile:.
Edit: Done :ok_hand:.

I just realized that the code somehow did not copy into the app entirely. I was missing the last few lines! Duh!

I am not sure where the change is when I see your screenshot.

It looks very nice. Excellent job.

1 Like

updated the post with purple highlights!

Regarding the Locale patch, it needs more work, if you want later I can send you the changes