-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprecomp.py
106 lines (82 loc) · 2.5 KB
/
precomp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import configparser
import http.client
import re
import urllib.request
import shutil
def info(msg):
print("II: " + msg)
WORK_DIR = os.path.expanduser('~') + "/map_build/"
config = configparser.ConfigParser()
def write_config():
with open('pygmap3.cfg', 'w') as configfile:
config.write(configfile)
def list_bounds():
config.read('pygmap3.cfg')
print()
info("set as used files:")
print()
for key in (config['precomp']):
print(" " + config['precomp'][key])
print()
os.chdir(WORK_DIR + "precomp")
info("local files:")
print()
for i in ['sea', 'bounds']:
dir = os.listdir()
list = [x for x in dir if x.startswith(i) if x.endswith(".zip")]
list = sorted(list, reverse=True)
for i in list:
print(" " + i)
print()
www = "osm.thkukuk.de"
path = "/data/"
info("files on thkukuk.de (*-latest not listed):")
for i in ['sea', 'bounds']:
try:
target = http.client.HTTPConnection(www)
target.request("GET", path)
htmlcontent = target.getresponse()
data = htmlcontent.read()
data = data.decode('utf8')
target.close()
except http.client.NotConnected:
print()
print(" can't connect to " + target)
print()
break
if i == "bounds":
pattern = re.compile(r'bounds-20\d{6}.zip')
elif i == "sea":
pattern = re.compile(r'sea-20\d{12}.zip')
data = sorted(pattern.findall(data), reverse=True)
list_new = []
for i in data:
if i not in list_new:
list_new.append(i)
for i in list_new:
print(" " + i)
print()
def fetch_bounds():
config.read('pygmap3.cfg')
os.chdir(WORK_DIR + "precomp")
www = "osm.thkukuk.de"
path = "/data/"
for i in ['sea', 'bounds']:
file = config['precomp'][i]
url = "http://" + www + path + file
if not os.path.exists(file):
print()
info("download " + url)
try:
uo = urllib.request.urlopen
with uo(url) as response, open(file, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
except urllib.error.URLError:
print()
print(" can't download " + file)
print()
break
os.chdir(WORK_DIR)