24

Smart Weather

Posted in Weather by enochou 632 days ago

Note

Somebody stole the API key to build their own app so now my API key has been blocked due to overuse. Going forward, you must register your own FREE account at openweathermap.org, and get your API key there. Then, simply go into the code and replace the key with your own. Each free API key is limited to 60 queries per minute.

Description

No need to enter your location or edit the code; it will use your public IP address to determine your approximate location and pull weather data (in celsius) from openweathermap.org. This dynamic location capability is extremely useful if you travel a lot.

I've separated the code into 4 different geeklets so you can format the 4 elements independently:

  1. Current temperature and weather condition
  2. Daily low and high temperature
  3. Sunrise and sunset times
  4. Current city and country

Examples

23°C, scattered clouds
-1°C, clear skies

Displaying and Editing Location

You can check the city and country that is being used (based on your public IP) by running the "citycountry.glet" geeklet. If the city/country displayed is not accurate, go into the code for any of the weather geeklets attached and look for the following two lines:

lon=${coords#*,}
lat=${coords%,*}

and manually replace them with numbers pertaining to your longitude and latitude. For example:

lon=-80.5454
lat=43.4715

Comments

User Avatar
cbombeck 594 days ago
Great Geeklet! How would I convert to Fahrenheit?
User Avatar
jaco 594 days ago
This worked for me:

In the following line of the script,

lat="$lat"&lon="$lon"&format=json&APPID=39ee99a92a0ebdc31db5a5d6092ed1cb&units=metric"`

Replace "metric" with "imperial".

Then on the bottom line, replace °C with °F
User Avatar
cbombeck 594 days ago
Thanks Jaco! Worked great
User Avatar
mlance 542 days ago
Hi! thanks for posting this! Is there any way to incorporate a extended 3 or 4 day forecast?
User Avatar
bill1956 483 days ago
This works great! Thanks! I would like to incorporate the weather icons (Apple uses in the notification sidebar would be great). Can you provide geeklets which would "pull" the weather icons based on the weather description.
User Avatar
lhempsworth 479 days ago
Thank you enochou! It works great.
User Avatar
kdavies 452 days ago
This worked great for a day. But today it doesn't seem to pull anything. I thought it might be so many people using your API key, but after several hours, it still won't pull anything. I love the concept, though.
User Avatar
enochou 385 days ago
I would suggest that you go and register for your own free API key at openweathermap.org. It looks like somebody is misusing my API key and, as a result, it got blocked by the admins at openweathermap.org.
User Avatar
FastByte123 436 days ago
Hey, enochou works grate and thanks for hosting.

Would it be hard to add the IP address's Region (ie. Province/State) to the citycountry.glet?
User Avatar
kdavies 369 days ago
I love this script. Works beautifully. I wondered if anyone found a way to pull the icon for current weather?
User Avatar
BigBadBobD 346 days ago
This really works well, I do have a couple of issues, one, the rounding won't work for me, I had to remove the command temp=`printf "%.*f\n" 0 $temp` If I leave it in, all my temps are 0

Also. I can only get a couple of these working. Appears some scripts are okay with the free api version some only worked with a $40.00 a month API (e.g. daily high and low temps using a forecast command with the Daily switch), which is too much for just a little weather on the desktop

Log in to comment or register here.