getting weather info - simple
Moderator: Martin
getting weather info - simple
I'm looking for a way to just make a global like global_weatheris
which just holds info like "Sunny", "Rain", "Tstorms", the basic weather options in my state. XD
maybe a second one for temperature in farenheit?
so i can use it for zooper since zooper won't get weather anymore
I don't need "today in saint pete the weather will be clear with partly cloudy skies and a temperature of 45 with a high of 89" Just current
Sunny
85
which just holds info like "Sunny", "Rain", "Tstorms", the basic weather options in my state. XD
maybe a second one for temperature in farenheit?
so i can use it for zooper since zooper won't get weather anymore
I don't need "today in saint pete the weather will be clear with partly cloudy skies and a temperature of 45 with a high of 89" Just current
Sunny
85
Re: getting weather info - simple
Hi,
You could use action HTTP Request to call an API like this one:
https://openweathermap.org/current
You can use action Script and function fromJSON to convert the response to an object structure and then access the data. Something like this might work (untested):
Regards,
Martin
You could use action HTTP Request to call an API like this one:
https://openweathermap.org/current
You can use action Script and function fromJSON to convert the response to an object structure and then access the data. Something like this might work (untested):
Code: Select all
data=fromJSON(response);
condition=data["weather"][0]["main"];
temp=data["main"]["temp"];
Martin
- digitalstone
- Posts: 342
- Joined: 21 Oct 2017 12:36
- Location: The Netherlands
Re: getting weather info - simple
Thanks Martin, that seems like a great source.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: getting weather info - simple
is that one of those sites that requires an api key and all that?
Re: getting weather info - simple
Yes, you need to sign up to get the free API keys. I just test using HTTP request to the city url. The response has no weather info at all, only kinda some template response. Analzying the XHR document loading at the Chrome PC developer tab, it shows there are API request using the same appid as used in the example page. I tried to request using this appid (b6907d289e10d714a6e88b30761fae22&id=5375480) and it works. Don't know if it has limit.
These are the variant that you can request from visiting the normal html page.
https://openweathermap.org/data/2.5/wea ... its=metric
https://openweathermap.org/data/2.5/for ... its=metric
https://openweathermap.org/data/2.5/for ... its=metric
Replace the 5375480 with the city ID you get from searching yours.
These are the variant that you can request from visiting the normal html page.
https://openweathermap.org/data/2.5/wea ... its=metric
https://openweathermap.org/data/2.5/for ... its=metric
https://openweathermap.org/data/2.5/for ... its=metric
Replace the 5375480 with the city ID you get from searching yours.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: getting weather info - simple
thanks so much, both of you. this worked great. I now have a section of my zooper widget that uses the weather from that link (set to my city) via automagic which checks the weather every 15 minutes (roughly) and then uses various images to show me the weather (a sun, sun and clouds, sun and mist, clouds and rain, etc etc)
Re: getting weather info - simple
This worked well for me, but I am also using dark sky to get forecast because it includes summary and some additional info I need. I originally used wunderground api up until yesterday then they dropped my api key. Took me a while to get that figured out using xpath now i have to figure out how to map values in JSON format.
I am going to attach a copy of the json as xml format for viewing, I need to get high and low from day 1 and day 2. Also need icon and summary. If could extract the formatted date that would be a bonus. Here is what I have that is obviously wrong.
Edit 3: I have corrected this and got it working. Just need to get the day from number.
Edit: I changed this and added ["data"] where required, but I still get error in log "could not convert 'temperatureHigh' to number". Maybe a hand with that?
Edit 2: if I comment out the "global_foretemphi" and the next line, then I get error 'rain is not a list or map' but rain is the string I'm looking for...
Edit 3: woohoo I got it but I could still use a hand pulling the day in short format to have on my widget. I'll hopefully get that if I keep plugging away. I changed the code above to my corrected code.
Edit 4: getting a little further, why is the first daily time showing as Sunday? Is that correct? Because the high and low showing is for tomorrow, Saturday. I've tried subtracting 5 hours but it's still Sunday.
here's an example response here as well if anyone can help me get the data points I want.
https://darksky.net/dev/docs#data-block
I am going to attach a copy of the json as xml format for viewing, I need to get high and low from day 1 and day 2. Also need icon and summary. If could extract the formatted date that would be a bonus. Here is what I have that is obviously wrong.
Edit 3: I have corrected this and got it working. Just need to get the day from number.
Code: Select all
forecast=fromJSON(fore);
log(forecast);
foretemphi1=forecast["daily"]["data"][0]["temperatureHigh"];
foretemplo1=forecast["daily"]["data"][0]["temperatureLow"];
global_foretemphi1="{foretemphi1,numberformat,0}";
global_foretemplo1="{foretemplo1,numberformat,0}";
//foreday1=forecast["daily"]["summary"][0];
//global_foreday1=replace("{foreday1}","Night","PM");
//global_weather=forecast;
foreicon=forecast["daily"]["icon"];
foretemphi2=forecast["daily"]["data"][1]["temperatureHigh"];
foretemplo2=forecast["daily"]["data"][1]["temperatureLow"];
global_foretemphi2="{foretemphi2,numberformat,0}";
global_foretemplo2="{foretemplo2,numberformat,0}";
//foreday2=evaluateXPathAsString(forecast, "/response/forecast/txt_forecast/forecastdays/forecastday[2]/title/text()");
//global_foreday2=replace("{foreday2}","Night","AM");
foreicon2=forecast["daily"]["data"][0]["icon"];
//updt=evaluateXPathAsString(forecast, "//observation_time");
//updt=replace(updt, "Last Updated on ", "");
foreicona=replace("{foreicon}","-day","");
foreicon2a=replace("{foreicon2}","-day","");
global_foreicon=replace("{foreicona}","-night","");
global_foreicon2=replace("{foreicon2a}","-night","");
global_forelong1=forecast["daily"]["summary"];
global_forelong2=forecast["daily"]["data"][0]["summary"];
rain=forecast["daily"]["data"][0]["precipProbability"];
log("{rain}");
Edit 2: if I comment out the "global_foretemphi" and the next line, then I get error 'rain is not a list or map' but rain is the string I'm looking for...
Edit 3: woohoo I got it but I could still use a hand pulling the day in short format to have on my widget. I'll hopefully get that if I keep plugging away. I changed the code above to my corrected code.
Edit 4: getting a little further, why is the first daily time showing as Sunday? Is that correct? Because the high and low showing is for tomorrow, Saturday. I've tried subtracting 5 hours but it's still Sunday.
Code: Select all
foreday1=forecast["daily"]["data"][0]["time"]. // 1552021200
global_foreday1="{foreday1, dateformat, EEE}"; // Sun
https://darksky.net/dev/docs#data-block
- Attachments
-
- weather4cast2.xml
- (8.59 KiB) Downloaded 892 times
Re: getting weather info - simple
I'm cheating for the time being and just getting the date via getDate and add hours where needed, but I would like to figure what I'm doing wrong with the dateformat of provided time. When I compare the forecast high and low with other apps it seems the first entry should be today and then the next tomorrow, etc. But I could be completely wrong...
Below is what I'm working on and I was thinking to share everything to make the widgets work once I get everything correct. Would be happy if anyone wants to contribute/collaborate.
I also made a small version for my android head unit status bar. I'm using custom fonts and getting weather info from both open weather(current) and dark sky (forecast) Eventually I will switch everything to dark sky I'm still learning how to parse the responses correctly.
Right now I just need to figure why the provided time is showing 2 days difference and day one is same day as day 2.
Edit: So when I format the given time (first one) is coming up as
07-18-1970 06:07. That cannot be correct.
Edit 2: I didn't think to ×1000 for milliseconds so I got it now. Last thing to do is find a way to get town name for widget without needing the extra request to open weather (dark sky does not provide actual name).
Below is what I'm working on and I was thinking to share everything to make the widgets work once I get everything correct. Would be happy if anyone wants to contribute/collaborate.
I also made a small version for my android head unit status bar. I'm using custom fonts and getting weather info from both open weather(current) and dark sky (forecast) Eventually I will switch everything to dark sky I'm still learning how to parse the responses correctly.
Right now I just need to figure why the provided time is showing 2 days difference and day one is same day as day 2.
Edit: So when I format the given time (first one) is coming up as
07-18-1970 06:07. That cannot be correct.
Edit 2: I didn't think to ×1000 for milliseconds so I got it now. Last thing to do is find a way to get town name for widget without needing the extra request to open weather (dark sky does not provide actual name).
- Attachments
-
- Widget example on home page
- Screenshot_20190308-102941_Samsung Experience Home.jpg (607.26 KiB) Viewed 22403 times
Re: getting weather info - simple
I've found solutions to most/all of my issues and posted the completed widget v1.0 here.
Re: getting weather info - simple
funny enough the site i was told to use is sometimes wrong as heck, or weird.
Like on some days it says "smoke", and i'm like "what, is the entire city on fire?"
go outside, completely clear.
some days when it's just overcast it says rain, all day.
Like on some days it says "smoke", and i'm like "what, is the entire city on fire?"
go outside, completely clear.
some days when it's just overcast it says rain, all day.