This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
forked from Percas/bag1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbag01_unzip.py
executable file
·95 lines (76 loc) · 3.13 KB
/
bag01_unzip.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
9 juni, Anton
version: 0.2
doel: uitpakken van de gezipte BAG XML bestanden
"""
# ################ import libraries ###############################
import sys
import os
import baglib
import zipfile
import time
from config import LOCATION
# ############### Define functions ################################
# Main function for this package:
def bag_unzip(current_month='testdata',
koppelvlak0='../data/00-zip/',
koppelvlak1='../data/01-xml/',
loglevel=True):
'''Uitpakken van door Kadaster gezipte XML bestanden.'''
tic = time.perf_counter()
print('-------------------------------------------')
print('------------- Start bag_unzip -------------')
print('-------------------------------------------')
inputdir = koppelvlak0 + current_month + '/'
outputdir = koppelvlak1 + current_month + '/'
unzip_files = os.listdir(inputdir)
bagobj_starts_with = {'vbo': '9999VBO',
'lig': '9999LIG',
'sta': '9999STA',
'pnd': '9999PND',
'num': '9999NUM',
'opr': '9999OPR',
'wpl': '9999WPL',
'wplgem': 'GEM-WPL-RELATIE'}
for bagobj in bagobj_starts_with.keys():
for unzip_file_name in unzip_files:
if unzip_file_name.startswith(bagobj_starts_with[bagobj]):
unzip_dir = outputdir + bagobj + '/'
unzip_file = inputdir + unzip_file_name
baglib.make_dir(unzip_dir)
print('\nUitpakken van bestand', unzip_file_name,
'\nin directory', inputdir,
'\nnaar directory', unzip_dir, '...')
ti = time.perf_counter()
with zipfile.ZipFile(unzip_file, 'r') as zip_ref:
zip_ref.extractall(unzip_dir)
to = time.perf_counter()
baglib.print_time(to - ti,
'file ' + unzip_file_name + ' unzipped in',
loglevel)
toc = time.perf_counter()
baglib.print_time(toc - tic, '\n------------- Einde bag_unzip in',
loglevel)
'''
# ########################################################################
print('------------- Start unzip_bag lokaal ------------- \n')
# ########################################################################
'''
if __name__ == '__main__':
print('-------------------------------------------')
print('-------------', LOCATION['OMGEVING'], '-----------')
print('-------------------------------------------\n')
DATADIR_IN = LOCATION['DATADIR_IN']
DATADIR_OUT = LOCATION['DATADIR_OUT']
DIR00 = DATADIR_IN + '00-zip/'
DIR01 = DATADIR_OUT + '01-xml/'
DIR02 = DATADIR_OUT + '02-csv/'
DIR03 = DATADIR_OUT + '03-bewerktedata/'
current_month = baglib.get_arg1(sys.argv, DIR00)
printit=True
bag_unzip(current_month=current_month,
koppelvlak0=DIR00,
koppelvlak1=DIR01,
loglevel=printit)