Created
June 17, 2020 16:12
-
-
Save tano297/f72827e05cc4a9ed174b6c9069aed0e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
from lxml import html | |
import json | |
import shutil | |
import cv2 | |
import numpy as np | |
# where to look for earthview | |
URL = "https://earthview.withgoogle.com/" | |
# request the html code to look for the link to the image | |
r = requests.get(URL) | |
if r.status_code == 200: | |
tree = html.fromstring(r.content) | |
body = tree.find("body") | |
data_photo = body.attrib.items()[1][1] | |
json_acceptable_string = data_photo.replace("'", "\"") | |
data_photo = json.loads(json_acceptable_string) | |
photoUrl = data_photo["photoUrl"] | |
print("Found the image:") | |
print(photoUrl) | |
else: | |
print("Could not find the image. Exiting.") | |
quit() | |
# if all went well, we download the image | |
r = requests.get(photoUrl, stream=True) | |
if r.status_code == 200: | |
img = cv2.imdecode(np.fromstring(r.raw.data, dtype=np.uint8), -1) | |
print('Image sucessfully Downloaded.') | |
cv2.imshow("Earth", img) | |
cv2.waitKey(0) | |
else: | |
print('Image Couldn\'t be retreived') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment