Browse Source

fix my tile grabber

master
Markus Bergholz 1 year ago
parent
commit
d91f394716
3 changed files with 59 additions and 5 deletions
  1. +2
    -2
      osm/getTiles.py
  2. +4
    -3
      osm/getTilesThreaded.py
  3. +53
    -0
      osm/getTilestest.py

+ 2
- 2
osm/getTiles.py View File

@ -22,7 +22,7 @@ headers = {
def base_url(zoom, x, y):
BASE_URL = 'http://{SERVER}/tile/{Z}/{X}/{Y}.png'
return BASE_URL.format(Z=zoom, X=x, Y=y, SERVER=server[randrange(3)])
return BASE_URL.format(Z=zoom, X=x, Y=y, SERVER=server)
def get_pngs(zoom):
progress = progressbar.ProgressBar()
@ -46,7 +46,7 @@ if __name__ == '__main__':
if r.get("stop"):
break
r.set('zoom', zoom)
print("fetching " + str(pow(2,zoom)+ pow(2,zoom)) + " tiles" )
print("fetching " + str(pow(2,zoom) * pow(2,zoom)) + " tiles" )
print("get zoom level: " + str(zoom))
get_pngs(zoom)

+ 4
- 3
osm/getTilesThreaded.py View File

@ -17,7 +17,6 @@ def rnd_file():
letters = string.ascii_lowercase
return "/tmp/" + ( ''.join(random.choice(letters) for i in range(32)) ) + ".png"
DEFAULT_WORKER = 5
thread = []
server = "88.198.17.138"
@ -33,7 +32,7 @@ headers = {
def base_url(zoom, x, y):
BASE_URL = 'http://{SERVER}/tile/{Z}/{X}/{Y}.png'
return BASE_URL.format(Z=zoom, X=x, Y=y, SERVER=server[randrange(3)])
return BASE_URL.format(Z=zoom, X=x, Y=y, SERVER=server)
def get_and_process_tile(x=None,zoom=None):
if None not in [x, zoom]:
@ -78,6 +77,8 @@ def get_pngs(zoom):
if __name__ == '__main__':
zoom = int(sys.argv[1])
DEFAULT_WORKER = int(sys.argv[2]) # use threads betweet 2 and 3?
# init 5 threads
for n in range(0, DEFAULT_WORKER):
@ -85,6 +86,6 @@ if __name__ == '__main__':
thread[n].start()
print("spawning thread " + str(n+1) + "/" + str(DEFAULT_WORKER))
print("fetching " + str(pow(2,zoom)+ pow(2,zoom)) + " tiles" )
print("fetching " + str(pow(2,zoom) * pow(2,zoom)) + " tiles" )
get_pngs(zoom)

+ 53
- 0
osm/getTilestest.py View File

@ -0,0 +1,53 @@
from math import pow
import requests
import sys
import progressbar
from pathlib import Path
import pngquant
from random import randrange
import redis
r = redis.Redis()
server = "78.47.76.92:8080"
HOME = '/mnt/osm'
OUTPUT = HOME + '/{Z}/{X}/{Y}.png'
pngquant.config(min_quality=50, max_quality=80)
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0'
}
def base_url(zoom, x, y):
BASE_URL = 'http://{SERVER}/data/v3/{Z}/{X}/{Y}.png'
return BASE_URL.format(Z=zoom, X=x, Y=y, SERVER=server)
def get_pngs(zoom):
progress = progressbar.ProgressBar()
max_x = int(pow(2,zoom)-1)
for x in progress(range(0, max_x)):
if r.get("stop"):
break
r.set("x", x)
for y in range(0, int(pow(2,zoom)-1)):
if r.get("stop"):
break
Path(HOME + '/{Z}/{X}'.format(X=x,Z=zoom)).mkdir(parents=True, exist_ok=True)
img_data = requests.get(base_url(zoom, x, y), headers=headers).content
#png = pngquant.quant_data(data=img_data)
with open(OUTPUT.format(Z=zoom,X=x,Y=y), 'wb') as handler:
handler.write(img_data)
r.set("y", y)
if __name__ == '__main__':
for zoom in range(0,10):
if r.get("stop"):
break
r.set('zoom', zoom)
print("fetching " + str(pow(2,zoom) * pow(2,zoom)) + " tiles" )
print("get zoom level: " + str(zoom))
get_pngs(zoom)

Loading…
Cancel
Save