I’ve been using a weather API lately to get the weather. It gives a summary, humidity, temperature, precipitation probability and much more! I’ve already parsed few things, you can continue to parse more if you choose. If anyone was interested they can check out my code:
EDIT: Many new things added and if you get an error then no weather information is available at that location
-- Weather
-- Use this function to perform your initial setup
function setup()
parameter.text("APIKey","")
parameter.integer("Longitude",-180,180)
parameter.integer("Latitude",-90,90)
--I registered an API Key that is free to use
APIKey = "7687f8ec79fcbe92cdd91a9589262a12"
parameter.action("Request Weather",request)
end
function request()
coord = string.format("%f,%f",Latitude,Longitude)
http.request("https://api.forecast.io/forecast/"..APIKey.."/"..coord,success)
end
-- This function gets called once every frame
function success(Data)
--Parse the Weather Info
--Find Summary
a=string.find(Data,"summary")
b=string.find(Data,",",a)
Summary = string.sub(Data,a+10,b-2)
Summary = "Summary: "..Summary
--Find Precipitation Intensity
a=string.find(Data,"precipIntensity")
b=string.find(Data,",",a)
PrecipitationIntensity = string.sub(Data,a+17,b-1)
PrecipitationIntensity = "Precipitation Intensity: "..PrecipitationIntensity
--Find Precipitation Probability
a=string.find(Data,"precipProbability")
b=string.find(Data,",",a)
PrecipitationProbability = string.sub(Data,a+19,b-1)
PrecipitationProbability = "Precipitation Probability: "..PrecipitationProbability
--Temperature
a=string.find(Data,"temperature")
b=string.find(Data,",",a)
Temperature = string.sub(Data,a+13,b-1)
Temperature = "Temperature: "..Temperature
--Dew Point
a=string.find(Data,"dewPoint")
b=string.find(Data,",",a)
Dew = string.sub(Data,a+10,b-1)
Dew = "Dew Point: "..Dew
--Humidity
a=string.find(Data,"humidity")
b=string.find(Data,",",a)
Hum = string.sub(Data,a+10,b-1)
Hum = "Humidity: "..Hum
--Wind Speed
a=string.find(Data,"windSpeed")
b=string.find(Data,",",a)
wispeed = string.sub(Data,a+11,b-1)
wispeed = "Wind Speed: "..wispeed
--Apparent Temp
a=string.find(Data,"apparentTemperature")
b=string.find(Data,",",a)
apt = string.sub(Data,a+21,b-1)
apt = "Feels Like: "..apt
--Cloud Cover
a=string.find(Data,"cloudCover")
b=string.find(Data,",",a)
cc = string.sub(Data,a+12,b-1)
cc = "Cloud Cover: "..cc
--Pressure
a=string.find(Data,"pressure")
b=string.find(Data,",",a)
ap = string.sub(Data,a+10,b-1)
ap = "Air Pressure: "..ap
--Wind Bearing
a=string.find(Data,"windBearing")
b=string.find(Data,",",a)
wb = string.sub(Data,a+13,b-1)
wb = "Wind Bearing: "..wb
-- Visibility
a=string.find(Data,"visibility")
b=string.find(Data,",",a)
v = string.sub(Data,a+12,b-1)
v = "Visibility: "..v
--Ozone
a=string.find(Data,"ozone")
b=string.find(Data,",",a)
o = string.sub(Data,a+11,b-2)
o = "Ozone: "..o
print(Summary)
print(PrecipitationIntensity)
print(PrecipitationProbability)
print(Temperature)
print(Hum)
print(Dew)
print(wispeed)
print(apt)
print(cc)
print(ap)
print(v)
print(o)
print(wb)
----------
---------------You can Continue to Find Variables In XML using this tempelate
--Print Data for Searching for Variables
-- print(Data)
end
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
end