wmts-exfiltrator/pkg/thread.py

24 lines
820 B
Python

import requests
from pkg.proxies import PROXIES
from .image import is_png
def download_tile(task):
row, col, base_url, r_headers, output = task
output_path = output / f"{row}_{col}.png"
if output_path.exists():
assert is_png(output_path)
return row, col, False
tile_url = f"{base_url}/{row}/{col}"
response = requests.get(tile_url, headers=r_headers, proxies=PROXIES)
if response.status_code == 200:
if not response.headers.get('Content-Type') == 'image/png':
raise Exception(f'Response gave Content-Type: {response.headers.get("Content-Type")}')
with open(output_path, "wb") as f:
f.write(response.content)
assert is_png(output_path)
return row, col, True
else:
print(f"Failed to download tile {row}_{col}")