Thanks.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Is it possible for computers to hook up to a REAL weather site/station and get weather information?
Started by stormchaser206, 26 January 2015 - 07:49 PMPosted 26 January 2015 - 08:49 PM
I'd like to know if it is possible to connect to a weather site (or station) and display the details on a monitor? Also, I'm talking about a real one.
Thanks.
Thanks.
Posted 26 January 2015 - 10:04 PM
Yes, similar to getting time of a website, you can see the commands your looking for here. (If i'm wrong thats because I dont play around with the http much)
Posted 27 January 2015 - 12:51 AM
Okay, I checked the page and kind of understand it. But - how do I get specific details from a page?
Posted 27 January 2015 - 01:03 AM
The page results come in as a string. Some webpages offer handy-dandy links which contain all their useful information in "plain text", so to speak, but usually you'll be filtering it out of HTML.
Either way, the answer involves string library functions.
Either way, the answer involves string library functions.
Posted 27 January 2015 - 01:34 AM
I checked that page but couldn't find a filter function (basically find a specific string and remove the rest. I also know that I will need to find multiple things so I don't know how that will turn out). Did I miss something on that page or is there not something like that? Sorry, I'm 0% LUA programmer and 100% ComputerCraft noob. But I shall (and will) learn!
Posted 27 January 2015 - 02:48 AM
It's easier if you can find a page that outputs as close to plaintext as possible. After a quick google search, I came up with this, from this question.
Posted 27 January 2015 - 03:59 AM
I checked that page but couldn't find a filter function
Start with string.find(). You'll need to read up on "patterns" in order to use it effectively - the function description links to a relevant tutorial.
Once you've got the hang of that, start playing with string.match(). The idea is to have it find a specific phrase (eg "the weather is", or "…", or "000", or a horizontal line break, or…), then also spit out whatever word comes after that.
Posted 27 January 2015 - 01:47 PM
I tried with string,find and used this code (yes, 100% noob code):
http.get(http://forecast.weather.gov/css/pointforecast.css, data)
print(data)
But when I use it, I get this:
bios:366: [string "weatherTest"]:1: '<name>' expected
Posted 27 January 2015 - 02:02 PM
You need the URL to be a string, as well as passing it into a variable
local data = http.get("http://forecast.weather.gov/css/pointforecast.css")
Posted 27 January 2015 - 02:06 PM
And then you need to pull the website data out of the handle that gives you, before closing it:
local webHandle = http.get("http://forecast.weather.gov/css/pointforecast.css")
local data = webHandle.readAll()
webHandle.close()
print(data)