1 comment

[ 5.3 ms ] story [ 15.3 ms ] thread
Didn't find the "Download All" option... but this should do:

    import json
    import os
    import re
    import requests

    url = 'https://earthview.withgoogle.com/%s'

    def get_data(slug=None):
        if not slug:
            html = read_url(url % '')
            slug = re.search('href="/(.*?)">Explore</a>', html).group(1)
        html = read_url(url % slug)
        data = json.loads(
            re.search('data-photo="(.*?)"', html).group(1).replace('&#34;', '"')
        )
        write_json('../json/%s.json' % slug, data)
        jpg = read_url(data['photoUrl'], binary=True)
        write_image('../jpg/%s.jpg' % slug, jpg)
        get_data(data['nextUrl'][1:])

    def read_url(url, binary=False):
        print('reading', url)
        r = requests.get(url)
        return r.content if binary else r.text

    def write_image(path, data):
        if not os.path.exists(path):
            print('writing', path)
            with open(path, 'wb') as f:
                f.write(data)

    def write_json(path, data):
        if not os.path.exists(path):
            print('writing', path)
            with open(path, 'w') as f:
                f.write(json.dumps(data, indent=4, sort_keys=True))

    if __name__ == '__main__':
        get_data()