Weather reports with curl
source link: https://www.tuicool.com/articles/hit/fIN3aqj
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
What is curl?
curl
is a program that is included in your Mac OSX distribution used for transferring data from or to a server. It uses many supported protocols (HTTP, HTTPS, FTP, SMTP and more).
Do you have curl?
Find the location of the curl
program (executable) with $ which curl
. This will return /usr/bin/curl
if you’re on Mac.
How do I use curl?
A simple http GET request can be made like this:
$ curl google.com
How to deal with 301 redirect
Notice that you get a 301 message that is address has been “moved”. You can add the flag -L, --location
(choose either) to “follow” redirects
$ curl -L google.com
$ curl --location google.com
How do I use curl to get the weather?
There is a service called wttr
that is set up to return weather reports when you curl their service.
For a full local weather report:
$ curl wttr.in
For todays weather report:
$ curl wttr.in?0
You can also specify a city or ski resort.
For todays weather report for New York:
curl wttr.in/~NewYork?0
Check if its snowy in your favorite ski resort – Charlotte Pass, Snowy Monaro, NSW, Australia
* Notice that wttr
is returning ASCII characters. You can save these to examine this in your text editor.
Congrats! You got the weather!
Note that you can curl any web service, even ones you build yourself .
Want to build your own weather service? We’ll do that next in the Part II of this series.
Bonus Section:
Can I curl my own websites?
Yes! If you followed our github pages tutorial you’ll find you can curl
your own website AND YOUR STATIC FILES
$ curl -L theptrk.github.io
<- website
$ curl -L theptrk.github.io/api/message.txt
<- static txt file
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK