0

I have an image on google (just google weather for [location]) and I would like to download it and display it through geektool. I have seen people use curl for yahoo weather before, but never for google. If you look at the source, the image's id is "wob_tci" and I was wondering if you can download and display that image.

The basic url for getting the weather is http://www.google.com/search?q=weather+for+[city]+[state/province/country]

Thanks for taking the time to help a n00b!

ZuluDeltaNiner
  • 725
  • 2
  • 11
  • 27

1 Answers1

1
  1. Make http request with realistic headers (user agent)

    #!/bin/bash
    
    curl \
        -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5" \
        -o weather.html \
        "https://www.google.com/search?q=weather%20for%20kazan"
    
  2. Parse image src with RegEx or XPath...

You'll have more fun if you do it yourself :)

Updated

Something like that:

#!/bin/bash

CITY="kazan"
SAVE_TO="weather.png"
IMAGE_URL=$(\
curl \
  -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5" \
  "https://www.google.com/search?q=weather%20for%20$CITY" | 
  grep -Poh 'src="(.+)" id="wob_tci"' |
  cut -d\" -f2
)

curl -o "$SAVE_TO" "https:$IMAGE_URL"
nomad
  • 64
  • 3