Parse openweathermap.org data into variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
BPet
Posts: 9
Joined: 22 Oct 2017, 08:50

Parse openweathermap.org data into variables

10 May 2024, 10:27

I have been trying for days to figure this out, but despite spending hours upon hours, I have not made much progress and I'm hoping this is an easy fix for someone in the forum :)

I have a text file from a request made to openweathermap.org that looks like this:

Code: Select all

{"lat":26.653,"lon":-80.247,"timezone":"America/New_York","timezone_offset":-14400,"current":{"dt":1715345600,"sunrise":1715337382,"sunset":1715385507,"temp":299.46,"feels_like":299.46,"pressure":1012,"humidity":82,"dew_point":296.14,"uvi":1.87,"clouds":20,"visibility":10000,"wind_speed":3.09,"wind_deg":210,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}]},"minutely":[{"dt":1715345640,"precipitation":0},{"dt":1715345700,"precipitation":0},{"dt":1715345760,"precipitation":0},{"dt":1715345820,"precipitation":0},{"dt":1715345880,"precipitation":0},{"dt":1715345940,"precipitation":0},{"dt":1715346000,"precipitation":0},{"dt":1715346060,"precipitation":0},{"dt":1715346120,"precipitation":0},{"dt":1715346180,"precipitation":0},{"dt":1715346240,"precipitation":0},{"dt":1715346300,"precipitation":0},{"dt":1715346360,"precipitation":0},{"dt":1715346420,"precipitation":0},{"dt":1715346480,"precipitation":0},{"dt":1715346540,"precipitation":0},{"dt":1715346600,"precipitation":0},{"dt":1715346660,"precipitation":0},{"dt":1715346720,"precipitation":0},{"dt":1715346780,"precipitation":0},{"dt":1715346840,"precipitation":0},{"dt":1715346900,"precipitation":0},{"dt":1715346960,"precipitation":0},{"dt":1715347020,"precipitation":0},{"dt":1715347080,"precipitation":0},{"dt":1715347140,"precipitation":0},{"dt":1715347200,"precipitation":0},{"dt":1715347260,"precipitation":0},{"dt":1715347320,"precipitation":0},{"dt":1715347380,"precipitation":0},{"dt":1715347440,"precipitation":0},{"dt":1715347500,"precipitation":0},{"dt":1715347560,"precipitation":0},{"dt":1715347620,"precipitation":0},{"dt":1715347680,"precipitation":0},{"dt":1715347740,"precipitation":0},{"dt":1715347800,"precipitation":0},{"dt":1715347860,"precipitation":0},{"dt":1715347920,"precipitation":0},{"dt":1715347980,"precipitation":0},{"dt":1715348040,"precipitation":0},{"dt":1715348100,"precipitation":0},{"dt":1715348160,"precipitation":0},{"dt":1715348220,"precipitation":0},{"dt":1715348280,"precipitation":0},{"dt":1715348340,"precipitation":0},{"dt":1715348400,"precipitation":0},{"dt":1715348460,"precipitation":0},{"dt":1715348520,"precipitation":0},{"dt":1715348580,"precipitation":0},{"dt":1715348640,"precipitation":0},{"dt":1715348700,"precipitation":0},{"dt":1715348760,"precipitation":0},{"dt":1715348820,"precipitation":0},{"dt":1715348880,"precipitation":0},{"dt":1715348940,"precipitation":0},{"dt":1715349000,"precipitation":0},{"dt":1715349060,"precipitation":0},{"dt":1715349120,"precipitation":0},{"dt":1715349180,"precipitation":0}],"hourly":[{"dt":1715342400,"temp":299.27,"feels_like":299.27,"pressure":1012,"humidity":79,"dew_point":295.34,"uvi":0.57,"clouds":16,"visibility":10000,"wind_speed":3.1,"wind_deg":203,"wind_gust":5.92,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715346000,"temp":299.46,"feels_like":299.46,"pressure":1012,"humidity":82,"dew_point":296.14,"uvi":1.87,"clouds":20,"visibility":10000,"wind_speed":3.94,"wind_deg":209,"wind_gust":5.86,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715349600,"temp":300.2,"feels_like":302.53,"pressure":1012,"humidity":75,"dew_point":295.39,"uvi":4.08,"clouds":16,"visibility":10000,"wind_speed":4.33,"wind_deg":207,"wind_gust":5.64,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715353200,"temp":301.77,"feels_like":304.28,"pressure":1012,"humidity":65,"dew_point":294.54,"uvi":6.7,"clouds":12,"visibility":10000,"wind_speed":4.31,"wind_deg":215,"wind_gust":5.52,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715356800,"temp":304.04,"feels_like":306.19,"pressure":1011,"humidity":53,"dew_point":293.35,"uvi":9.05,"clouds":8,"visibility":10000,"wind_speed":4.39,"wind_deg":223,"wind_gust":5.41,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"pop":0},{"dt":1715360400,"temp":306.88,"feels_like":308.37,"pressure":1011,"humidity":41,"dew_point":291.8,"uvi":10.39,"clouds":4,"visibility":10000,"wind_speed":4.51,"wind_deg":252,"wind_gust":5.18,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"pop":0},{"dt":1715364000,"temp":309.7,"feels_like":309.41,"pressure":1011,"humidity":27,"dew_point":287.96,"uvi":10.22,"clouds":0,"visibility":10000,"wind_speed":5.16,"wind_deg":277,"wind_gust":5.37,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"pop":0},{"dt":1715367600,"temp":310.19,"feels_like":309.64,"pressure":1010,"humidity":25,"dew_point":286.99,"uvi":8.56,"clouds":1,"visibility":10000,"wind_speed":5.07,"wind_deg":283,"wind_gust":5.36,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"pop":0},{"dt":1715371200,"temp":310.45,"feels_like":309.78,"pressure":1009,"humidity":24,"dew_point":286.5,"uvi":5.96,"clouds":2,"visibility":10000,"wind_speed":4.6,"wind_deg":263,"wind_gust":5.06,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"pop":0},{"dt":1715374800,"temp":310.11,"feels_like":309.3,"pressure":1009,"humidity":24,"dew_point":286.23,"uvi":3.27,"clouds":36,"visibility":10000,"wind_speed":5.14,"wind_deg":271,"wind_gust":5.27,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"pop":0},{"dt":1715378400,"temp":309.11,"feels_like":308.15,"pressure":1009,"humidity":25,"dew_point":286.33,"uvi":1.36,"clouds":29,"visibility":10000,"wind_speed":5.51,"wind_deg":283,"wind_gust":5.01,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"pop":0},{"dt":1715382000,"temp":307.1,"feels_like":306.2,"pressure":1009,"humidity":29,"dew_point":286.89,"uvi":0.35,"clouds":25,"visibility":10000,"wind_speed":5.24,"wind_deg":276,"wind_gust":6.29,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"pop":0},{"dt":1715385600,"temp":303.96,"feels_like":303.19,"pressure":1009,"humidity":35,"dew_point":287.04,"uvi":0,"clouds":20,"visibility":10000,"wind_speed":4.26,"wind_deg":262,"wind_gust":9.07,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"pop":0},{"dt":1715389200,"temp":302.36,"feels_like":301.88,"pressure":1010,"humidity":39,"dew_point":287.16,"uvi":0,"clouds":0,"visibility":10000,"wind_speed":4.69,"wind_deg":265,"wind_gust":10.78,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715392800,"temp":301.14,"feels_like":301.33,"pressure":1010,"humidity":47,"dew_point":288.8,"uvi":0,"clouds":0,"visibility":10000,"wind_speed":4.66,"wind_deg":265,"wind_gust":10.81,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715396400,"temp":299.72,"feels_like":299.72,"pressure":1010,"humidity":59,"dew_point":291.06,"uvi":0,"clouds":0,"visibility":10000,"wind_speed":4.27,"wind_deg":267,"wind_gust":10.04,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715400000,"temp":298.49,"feels_like":298.91,"pressure":1010,"humidity":70,"dew_point":292.45,"uvi":0,"clouds":0,"visibility":10000,"wind_speed":4.25,"wind_deg":275,"wind_gust":10.38,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715403600,"temp":297.59,"feels_like":298.13,"pressure":1010,"humidity":78,"dew_point":293.38,"uvi":0,"clouds":0,"visibility":10000,"wind_speed":3.99,"wind_deg":275,"wind_gust":9.95,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715407200,"temp":296.93,"feels_like":297.56,"pressure":1010,"humidity":84,"dew_point":293.99,"uvi":0,"clouds":0,"visibility":10000,"wind_speed":3.75,"wind_deg":282,"wind_gust":9.86,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715410800,"temp":296.64,"feels_like":297.37,"pressure":1010,"humidity":89,"dew_point":294.65,"uvi":0,"clouds":0,"visibility":10000,"wind_speed":3.48,"wind_deg":283,"wind_gust":9.3,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715414400,"temp":296.56,"feels_like":297.36,"pressure":1010,"humidity":92,"dew_point":295.13,"uvi":0,"clouds":4,"visibility":10000,"wind_speed":2.97,"wind_deg":279,"wind_gust":8.43,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715418000,"temp":296.37,"feels_like":297.2,"pressure":1010,"humidity":94,"dew_point":295.27,"uvi":0,"clouds":11,"visibility":10000,"wind_speed":2.72,"wind_deg":266,"wind_gust":7.66,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"pop":0},{"dt":1715421600,"temp":296.3,"feels_like":297.13,"pressure":1010,"humidity":94,"dew_point":295.31,"uvi":0,"clouds":17,"visibility":10000,"wind_speed":2.51,"wind_deg":255,"wind_gust":6.89,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"pop":0},{"dt":1715425200,"temp":296.34,"feels_like":297.17,"pressure":1011,"humidity":94,"dew_point":295.26,"uvi":0,"clouds":21,"visibility":10000,"wind_speed":2.43,"wind_deg":254,"wind_gust":6.61,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715428800,"temp":298.21,"feels_like":299.02,"pressure":1012,"humidity":86,"dew_point":295.59,"uvi":0.56,"clouds":23,"visibility":10000,"wind_speed":3.31,"wind_deg":267,"wind_gust":7.03,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715432400,"temp":300.72,"feels_like":303.23,"pressure":1012,"humidity":72,"dew_point":295.16,"uvi":1.78,"clouds":10,"visibility":10000,"wind_speed":3.96,"wind_deg":274,"wind_gust":6.43,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"pop":0},{"dt":1715436000,"temp":302.91,"feels_like":305.16,"pressure":1012,"humidity":58,"dew_point":293.66,"uvi":3.65,"clouds":14,"visibility":10000,"wind_speed":4.38,"wind_deg":273,"wind_gust":6,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715439600,"temp":304.7,"feels_like":306.49,"pressure":1012,"humidity":49,"dew_point":292.88,"uvi":6.27,"clouds":7,"visibility":10000,"wind_speed":4.74,"wind_deg":278,"wind_gust":6.6,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"pop":0},{"dt":1715443200,"temp":305.92,"feels_like":307.93,"pressure":1011,"humidity":46,"dew_point":293.03,"uvi":9.06,"clouds":14,"visibility":10000,"wind_speed":4.71,"wind_deg":275,"wind_gust":6.64,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715446800,"temp":306.89,"feels_like":309.18,"pressure":1011,"humidity":44,"dew_point":292.92,"uvi":10.43,"clouds":21,"visibility":10000,"wind_speed":5.13,"wind_deg":281,"wind_gust":7.1,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0},{"dt":1715450400,"temp":306.74,"feels_like":308.64,"pressure":1010,"humidity":43,"dew_point":292.72,"uvi":10.24,"clouds":32,"visibility":10000,"wind_speed":4.99,"wind_deg":276,"wind_gust":7.29,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"pop":0},{"dt":1715454000,"temp":305.96,"feels_like":307.76,"pressure":1010,"humidity":45,"dew_point":292.51,"uvi":8.66,"clouds":94,"visibility":10000,"wind_speed":4.25,"wind_deg":253,"wind_gust":7.08,"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"pop":0},{"dt":1715457600,"temp":306.51,"feels_like":308.48,"pressure":1009,"humidity":44,"dew_point":292.62,"uvi":6.1,"clouds":74,"visibility":10000,"wind_speed":5.22,"wind_deg":235,"wind_gust":7.23,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"pop":0},{"dt":1715461200,"temp":307.93,"feels_like":309.4,"pressure":1008,"humidity":38,"dew_point":291.7,"uvi":3.42,"clouds":51,"visibility":10000,"wind_speed":6.03,"wind_deg":245,"wind_gust":7.49,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"pop":0},{"dt":1715464800,"temp":307.78,"feels_like":309.14,"pressure":1008,"humidity":38,"dew_point":291.54,"uvi":1.42,"clouds":36,"visibility":10000,"wind_speed":6.73,"wind_deg":244,"wind_gust":8.69,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"pop":0},{"dt":1715468400,"temp":306.88,"feels_like":308.12,"pressure":1008,"humidity":40,"dew_point":291.76,"uvi":0.36,"clouds":30,"visibility":10000,"wind_speed":5.75,"wind_deg":238,"wind_gust":8.21,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"pop":0},{"dt":1715472000,"temp":304.33,"feels_like":305.67,"pressure":1009,"humidity":48,"dew_point":292.2,"uvi":0,"clouds":25,"visibility":10000,"wind_speed":6.37,"wind_deg":249,"wind_gust":9.57,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"pop":0},{"dt":1715475600,"temp":302.11,"feels_like":304.27,"pressure":1010,"humidity":61,"dew_point":293.65,"uvi":0,"clouds":3,"visibility":10000,"wind_speed":4.3,"wind_deg":271,"wind_gust":7.74,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715479200,"temp":300.52,"feels_like":302.85,"pressure":1010,"humidity":72,"dew_point":294.89,"uvi":0,"clouds":1,"visibility":10000,"wind_speed":3.61,"wind_deg":307,"wind_gust":8.3,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715482800,"temp":299.19,"feels_like":299.19,"pressure":1011,"humidity":80,"dew_point":295.5,"uvi":0,"clouds":1,"visibility":10000,"wind_speed":3.58,"wind_deg":322,"wind_gust":6.71,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715486400,"temp":298.08,"feels_like":298.87,"pressure":1012,"humidity":86,"dew_point":295.49,"uvi":0,"clouds":1,"visibility":10000,"wind_speed":3.13,"wind_deg":324,"wind_gust":5.82,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715490000,"temp":297.56,"feels_like":298.33,"pressure":1012,"humidity":87,"dew_point":295.21,"uvi":0,"clouds":1,"visibility":10000,"wind_speed":2.86,"wind_deg":337,"wind_gust":5.45,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715493600,"temp":297.33,"feels_like":298.05,"pressure":1012,"humidity":86,"dew_point":294.75,"uvi":0,"clouds":3,"visibility":10000,"wind_speed":2.96,"wind_deg":344,"wind_gust":5.59,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"pop":0},{"dt":1715497200,"temp":296.87,"feels_like":297.54,"pressure":1012,"humidity":86,"dew_point":294.3,"uvi":0,"clouds":12,"visibility":10000,"wind_speed":2.68,"wind_deg":349,"wind_gust":5.34,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"pop":0},{"dt":1715500800,"temp":296.57,"feels_like":297.21,"pressure":1012,"humidity":86,"dew_point":294.05,"uvi":0,"clouds":12,"visibility":10000,"wind_speed":2.45,"wind_deg":352,"wind_gust":4.96,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"pop":0},{"dt":1715504400,"temp":296.22,"feels_like":296.83,"pressure":1012,"humidity":86,"dew_point":293.75,"uvi":0,"clouds":11,"visibility":10000,"wind_speed":2.21,"wind_deg":353,"wind_gust":4.61,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"pop":0},{"dt":1715508000,"temp":295.88,"feels_like":296.45,"pressure":1012,"humidity":86,"dew_point":293.44,"uvi":0,"clouds":12,"visibility":10000,"wind_speed":2.11,"wind_deg":350,"wind_gust":4.29,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"pop":0},{"dt":1715511600,"temp":295.95,"feels_like":296.51,"pressure":1013,"humidity":85,"dew_point":293.17,"uvi":0,"clouds":12,"visibility":10000,"wind_speed":1.83,"wind_deg":352,"wind_gust":3.66,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"pop":0}],"daily":[{"dt":1715360400,"sunrise":1715337382,"sunset":1715385507,"moonrise":1715344020,"moonset":1715396700,"moon_phase":0.09,"summary":"Expect a day of partly cloudy with clear spells","temp":{"day":306.88,"min":297.42,"max":310.45,"night":299.72,"eve":307.1,"morn":298.38},"feels_like":{"day":308.37,"night":299.72,"eve":306.2,"morn":299.05},"pressure":1011,"humidity":41,"dew_point":291.8,"wind_speed":5.51,"wind_deg":283,"wind_gust":10.81,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":4,"pop":0,"uvi":10.39},{"dt":1715446800,"sunrise":1715423746,"sunset":1715471941,"moonrise":1715433900,"moonset":0,"moon_phase":0.13,"summary":"Expect a day of partly cloudy with clear spells","temp":{"day":306.89,"min":296.3,"max":307.93,"night":299.19,"eve":306.88,"morn":296.34},"feels_like":{"day":309.18,"night":299.19,"eve":308.12,"morn":297.17},"pressure":1011,"humidity":44,"dew_point":292.92,"wind_speed":6.73,"wind_deg":244,"wind_gust":10.38,"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":21,"pop":0,"uvi":10.43},{"dt":1715533200,"sunrise":1715510112,"sunset":1715558375,"moonrise":1715523900,"moonset":1715486520,"moon_phase":0.16,"summary":"Expect a day of partly cloudy with clear spells","temp":{"day":306.85,"min":295.88,"max":307.64,"night":299.13,"eve":301.59,"morn":295.95},"feels_like":{"day":306.57,"night":299.13,"eve":302.66,"morn":296.51},"pressure":1013,"humidity":33,"dew_point":288.35,"wind_speed":5.7,"wind_deg":75,"wind_gust":6.33,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":26,"pop":0,"uvi":10.6},{"dt":1715619600,"sunrise":1715596479,"sunset":1715644810,"moonrise":1715613960,"moonset":1715575860,"moon_phase":0.19,"summary":"There will be partly cloudy today","temp":{"day":304.96,"min":297.59,"max":304.96,"night":299.77,"eve":299.88,"morn":297.82},"feels_like":{"day":306.29,"night":299.77,"eve":301.15,"morn":298.41},"pressure":1015,"humidity":46,"dew_point":291.95,"wind_speed":6.4,"wind_deg":108,"wind_gust":7.11,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":82,"pop":0,"uvi":8.85},{"dt":1715706000,"sunrise":1715682846,"sunset":1715731244,"moonrise":1715703780,"moonset":1715664780,"moon_phase":0.22,"summary":"You can expect partly cloudy in the morning, with clearing in the afternoon","temp":{"day":308.08,"min":298.96,"max":308.08,"night":300.59,"eve":302.68,"morn":300.41},"feels_like":{"day":310.85,"night":302.67,"eve":305.29,"morn":302.75},"pressure":1012,"humidity":42,"dew_point":293.5,"wind_speed":7.77,"wind_deg":151,"wind_gust":10,"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":92,"pop":0,"uvi":0.47},{"dt":1715792400,"sunrise":1715769215,"sunset":1715817678,"moonrise":1715793540,"moonset":1715753280,"moon_phase":0.25,"summary":"The day will start with clear sky through the late morning hours, transitioning to partly cloudy","temp":{"day":311.53,"min":298.8,"max":311.53,"night":300.61,"eve":305.89,"morn":301.08},"feels_like":{"day":313.63,"night":301.83,"eve":306.33,"morn":303.3},"pressure":1011,"humidity":31,"dew_point":291.57,"wind_speed":5.5,"wind_deg":262,"wind_gust":9.86,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":43,"pop":0,"uvi":1},{"dt":1715878800,"sunrise":1715855585,"sunset":1715904112,"moonrise":1715883120,"moonset":1715841540,"moon_phase":0.29,"summary":"You can expect partly cloudy in the morning, with rain in the afternoon","temp":{"day":311.06,"min":297.66,"max":311.06,"night":299.14,"eve":302.36,"morn":299.47},"feels_like":{"day":311.79,"night":299.14,"eve":305.58,"morn":299.47},"pressure":1013,"humidity":28,"dew_point":289.9,"wind_speed":4.69,"wind_deg":177,"wind_gust":7.85,"weather":[{"id":502,"main":"Rain","description":"heavy intensity rain","icon":"10d"}],"clouds":70,"pop":1,"rain":15.66,"uvi":1},{"dt":1715965200,"sunrise":1715941957,"sunset":1715990546,"moonrise":1715972640,"moonset":1715929680,"moon_phase":0.32,"summary":"Expect a day of partly cloudy with clear spells","temp":{"day":309.85,"min":298.8,"max":309.85,"night":302.09,"eve":303.61,"morn":300.6},"feels_like":{"day":310.41,"night":305.04,"eve":306.66,"morn":303.92},"pressure":1014,"humidity":30,"dew_point":289.79,"wind_speed":6.37,"wind_deg":149,"wind_gust":8.74,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":83,"pop":0.8,"uvi":1}]}

and I would like to put the data into variables that I can send to another program...so I need variables like: current_temp, current_sunrise etc...

it seems I have to use something like JSON.ahk and so I put a copy in a /lib folder and cobbled together the following ahk script from other's in the forum:

Code: Select all

#Include <JSON>

FileRead, var, C:\Program Files (x86)\Cinemar\Batch Files\openweathermap.txt	; get JSON string
msgbox % var				; show string


obj := JSON.load(var)		; load string into object

msgbox % obj

msgbox % obj.statusCode "`n" obj.success "`n" obj.result.totalRecords
msgbox % obj.result.items[1].id "`n"  obj.result.items[1].name
msgbox % obj.result.items[2].id "`n"  obj.result.items[2].name
my thinking is that if I can get the msgboxes to show the correct info, then I'm heading in the right direction. Then, I need a way to pick apart the individual items to load them into variables that I can send to the other program. (I already figured out how to send them to the other program by calling that program's executable)

As you can see, I'm not that knowledgeable in working with this type of data and so I appreciated any help you can provide! Thanks!
ShatterCoder
Posts: 84
Joined: 06 Oct 2016, 15:57

Re: Parse openweathermap.org data into variables

10 May 2024, 12:31

I get the feeling that perhaps you are confused about what JSON.load() actually does. It simply creates an object/array that mirrors the JSON key : value pairs listed in the input. take for example the following JSON input

Code: Select all

{
   "current": {
      "clouds": 20,
      "dew_point": "296.14",
      "dt": 1715345600,
      "feels_like": "299.46",
      "humidity": 82,
      "pressure": 1012,
      "sunrise": 1715337382,
      "sunset": 1715385507,
      "temp": "299.46",
      "uvi": "1.87",
      "visibility": 10000
      }
}
would result in an array having the key "current" which contains another array having the keys "clouds" - "visibility"
so you could address that in ahk using something like:

Code: Select all

data =
(
{
   "current": {
      "clouds": 20,
      "dew_point": "296.14",
      "dt": 1715345600,
      "feels_like": "299.46",
      "humidity": 82,
      "pressure": 1012,
      "sunrise": 1715337382,
      "sunset": 1715385507,
      "temp": "299.46",
      "uvi": "1.87",
      "visibility": 10000
      }
}
)

obj := JSON.load(data)

msgbox % obj.current.clouds ;will show 20
msgbox % obj.current.humidity ;will show 82
Hope this helps
BPet
Posts: 9
Joined: 22 Oct 2017, 08:50

Re: Parse openweathermap.org data into variables

10 May 2024, 13:12

Thanks -ShatterCoder! You are correct, I am confused, lol

Your example is helpful! So, it seems like I need to create the data variable that contains the structure of the input text file. Seems like I can basically cut and paste the entire text file to use to create the data variable, with the extra (‘s

I see how I can obtain the items that only have one instance and then set them to a variable to output to another program.

For all of the minutely and hourly data, how would you call up the “dt” key since there are numerous instances occurring in the same structure level?

Thanks again!
BPet
Posts: 9
Joined: 22 Oct 2017, 08:50

Re: Parse openweathermap.org data into variables

10 May 2024, 13:44

Ah, figured it out with your guidance :)

this works:

Code: Select all

#Include <JSON>

FileRead, var, C:\Program Files (x86)\Cinemar\Batch Files\openweathermap.txt	; get JSON string

obj := JSON.load(var)		; load string into object

msgbox % obj.current.clouds
msgbox % obj.minutely.1.dt
I can pull out any of the specific data like it works in the msgbox example and assign a variable to it to send it off to another program.
BPet
Posts: 9
Joined: 22 Oct 2017, 08:50

Re: Parse openweathermap.org data into variables

11 May 2024, 22:34

almost there...how do I put a variable in the object request for data. I want to run the request through a loop that runs 8 times and increments the counter each time so I can pull the max temp out of the json object for 8 days, like this:

Code: Select all

count := 1
loop, 8
msgbox % obj.daily.count.temp.max *9/5-459.67
count ++

of course AutoHotkey is looking for a obj structure that has the word "count" in it, when I really want it to look for:
obj.daily.1.temp.max *9/5-459.67
obj.daily.2.temp.max *9/5-459.67
obj.daily.3.temp.max *9/5-459.67
...

Thanks again for your help!
User avatar
Chunjee
Posts: 1452
Joined: 18 Apr 2014, 19:05
Contact:

Re: Parse openweathermap.org data into variables

12 May 2024, 08:27

I believe that would square bracket notation:

Code: Select all

loop, 8 {
	msgbox, % obj.daily[A_Index]temp.max *9/5-459.67
}

https://www.autohotkey.com/docs/v1/Objects.htm#Usage_Objects
All types of objects support both array syntax (brackets) and object syntax (dots)



If you prefer your own count variable it might look like:

Code: Select all

count := 0
loop, 8 {
	count++
	msgbox, % obj.daily[count]temp.max *9/5-459.67
}
BPet
Posts: 9
Joined: 22 Oct 2017, 08:50

Re: Parse openweathermap.org data into variables

12 May 2024, 08:33

Thanks Chunjee, but I tried with the square bracket and it doesn't work. It just returns a blank message box. I have tried lots of various ways, but I just can't get it to pull the value. Just in case, I tried replacing the [A_Index] with .1. , just to be sure my Json is working properly, and it pulls the value no problem.

I am using AutoHotkey version 1.1.22.03 would that matter?

Thanks again!
BPet
Posts: 9
Joined: 22 Oct 2017, 08:50

Re: Parse openweathermap.org data into variables

12 May 2024, 08:41

thanks for the help, actually, if I add another "." after the brackets, it works:

Code: Select all

count := 0
loop, 2 {
	count++
	msgbox, % obj.daily[count].temp.max *9/5-459.67
}

BPet
Posts: 9
Joined: 22 Oct 2017, 08:50

Re: Parse openweathermap.org data into variables

12 May 2024, 15:59

Is it possible to compare the day of the month taken from FormatTime vs taking it from a conversion of unixTime. I want to perform some actions if they are different. I'm assuming that this is some type of mismatch type issue, but after hours playing with it - I can't seem to resolve it. The message box shows the same number day, which is 12 - but the system does not think they are equal...

Code: Select all

FormatTime, NumDayinMonth,, dd 
loop, 2 {	

	unixTime := obj.hourly[A_Index].dt
	time := 1970
	time += unixTime, s
	utcTime := time 

	diff -= A_NowUTC, h
	time += diff, h
	localTime := time

	StringMid, MLVarfordaynum, localTime, 7, 2 ; 
	
	msgbox, % NumDayinMonth MLVarfordaynum
	

	if NumDayinMonth = MLVarfordaynum
	{
	msgbox, "they are equal"
	}
User avatar
Chunjee
Posts: 1452
Joined: 18 Apr 2014, 19:05
Contact:

Re: Parse openweathermap.org data into variables

12 May 2024, 23:31

BPet wrote:
12 May 2024, 15:59
unixTime.
This hasn't received robust testing or anything but

Code: Select all

jsonVal := "1715345600"
currentTime := "1715599151"
msgbox, % UnixTimestampDifference(currentTime, jsonVal)
; => 2.934618
; ie 2.9 days difference


; assumes Unix Epoch in seconds! NOT milliseconds
UnixTimestampDifference(utcDate1, utcDate2) {
	; Calculate the difference in seconds
	diffSeconds := Abs((utcDate1 + 0) - (utcDate2 + 0))
	
	; Convert the difference from seconds to days
	diffDays := diffSeconds / (60 * 60 * 24)
	
	; Return the difference in days
	return diffDays
}
It won't tell you if they are both in November but obviously anything lower than 30ish days is not older than a month


You can calculate this on your own by taking the ahk time -= 19700101000000, s I think

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: arrondark and 115 guests