-
Notifications
You must be signed in to change notification settings - Fork 0
/
udelej-gpx-bez-aktivace.py
92 lines (73 loc) · 3.59 KB
/
udelej-gpx-bez-aktivace.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
#/usr/bin/env python
# -*- coding: utf-8 -*-
# tento script vezme soubor *.csv ktery najde ve slozce, pak si vezme soubor okff.gpx ktery najde ve slozce
# a vytvori soubor okff-noactivation.gpx ktery ulozi a v kterem budou pouze a jen okff ze souboru .csv doplnene o presnou polohu
# cele to slouzi k tomu, aby se dala do LOCUSU pridat dalsi vrstva s OKFF ktere jeste nikdo neaktivoval
# skript je funkcni v Linuxu Mint a Python3
# pomoci "pip install" je treba naistalovat wget, zipfile
# pro spravny beh pod windows10 je treba na radku 45 odstranit parametr "encoding" kompletne
# udelal Michal OK1SIM pro komunitu OKFF ... 73 & 44
# pouzivej dle libosti, upravuj, sir, proste je to tvoje ...
import wget
from zipfile import ZipFile
import os
import shutil
from urllib.request import urlopen
i = 0
okff_celkem_v_gpx_z_okffcz = 0
okff_celkem_v_csv_z_wwff = 0
print("\n\n\nScript zacal pracovat ...")
print("\nStahuji aktualni kompletni gpx z okff.cz ...")
if(os.path.isfile('okff-without-activation.gpx')):
os.remove('okff-without-activation.gpx')
if(os.path.isfile('okff.zip')):
os.remove('okff-without-activation.gpx')
shutil.rmtree('/okff', ignore_errors=True)
url = 'http://okff.wz.cz/download/okff.zip'
wget.download(url, 'okff.zip')
ZipFile('okff.zip').extractall('okff')
os.remove('okff.zip')
with open("okff-without-activation.gpx","a") as file:
file.write('<?xml version="1.0" encoding="windows-1250" standalone="no" ?>\n\n')
file.write('<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="GPS Data Team ( http://www.gps-data-team.com )">\n\n')
try:
with open('./okff/okff.gpx') as f: # windows varianta
exist_lines = list(f)
for exist_line in exist_lines:
if "OKFF-" in exist_line:
okff_celkem_v_gpx_z_okffcz += 1
okff_celkem_v_csv_z_wwff = 0
with open('bez-aktivace.csv') as b:
new_lines = list(b)
for new_line in new_lines:
okff_celkem_v_csv_z_wwff += 1
if new_line.strip() in exist_line:
#print(exist_line)
i = i + 1
with open("okff-without-activation.gpx","a") as file:
file.write(exist_line)
except:
with open('./okff/okff.gpx', encoding = 'ISO-8859-1') as f: # linux varianta
exist_lines = list(f)
for exist_line in exist_lines:
if "OKFF-" in exist_line:
okff_celkem_v_gpx_z_okffcz += 1
okff_celkem_v_csv_z_wwff = 0
with open('bez-aktivace.csv') as b:
new_lines = list(b)
for new_line in new_lines:
okff_celkem_v_csv_z_wwff += 1
if new_line.strip() in exist_line:
#print(exist_line)
i = i + 1
with open("okff-without-activation.gpx","a") as file:
file.write(exist_line)
with open("okff-without-activation.gpx","a") as file:
file.write("</gpx>")
shutil.rmtree('/okff', ignore_errors=True)
print("\n")
print("\nCelkem zpracovano z okff.gpx radku: ",okff_celkem_v_gpx_z_okffcz)
print("\nCelkem je radku v CSV souboru z wwff: ",okff_celkem_v_csv_z_wwff)
print("\nCelkem nalezeno v okff.gpx mist bez aktivace: ", i)
print("\nVytvoren soubor okff-without-activation.gpx.")
print("\n")