Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
Get Baden-Württemberg CityGML Opendata
Commits
862ff084
Commit
862ff084
authored
Jul 03, 2024
by
Eric Duminil
Browse files
Adding tests template
parent
a1776570
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
862ff084
...
...
@@ -5,6 +5,7 @@
*.step
*.txt
*.pdf
*.pyc
cache
input
plz/plz-5stellig.geojson
get_coordinates_by_zipcode.py
View file @
862ff084
...
...
@@ -30,34 +30,34 @@ from shapely.ops import unary_union
INPUT_FOLDER
=
Path
(
'plz'
)
PLZ_FILENAME
=
'plz-5stellig.geojson'
PLZ_SHAPE
S
=
INPUT_FOLDER
/
PLZ_FILENAME
PLZ_SHAPE
_FILE
=
INPUT_FOLDER
/
PLZ_FILENAME
def
download_if_needed
():
if
not
PLZ_SHAPE
S
.
exists
():
def
_
download_
plz_shapes_
if_needed
():
if
not
PLZ_SHAPE
_FILE
.
exists
():
from
tqdm
import
tqdm
import
requests
URL
=
"https://downloads.suche-postleitzahl.org/v2/public/"
+
PLZ_FILENAME
response
=
requests
.
get
(
URL
,
stream
=
True
)
INPUT_FOLDER
.
mkdir
(
exist_ok
=
True
)
with
open
(
PLZ_SHAPE
S
,
"wb"
)
as
handle
:
with
open
(
PLZ_SHAPE
_FILE
,
"wb"
)
as
handle
:
for
data
in
tqdm
(
response
.
iter_content
(
chunk_size
=
1024
),
unit
=
'kB'
):
handle
.
write
(
data
)
def
parse_data
():
def
_get_plz_shapes
():
print
(
"Parsing %s..."
%
PLZ_FILENAME
)
download_if_needed
()
_
download_
plz_shapes_
if_needed
()
try
:
with
open
(
PLZ_SHAPE
S
)
as
f
:
with
open
(
PLZ_SHAPE
_FILE
)
as
f
:
print
(
' Done'
)
return
json
.
load
(
f
)
except
json
.
decoder
.
JSONDecodeError
:
PLZ_SHAPE
S
.
unlink
()
PLZ_SHAPE
_FILE
.
unlink
()
raise
AttributeError
(
f
"
{
PLZ_FILENAME
}
seems to be damaged. Removing it. Please try again!"
)
def
get_
plz
(
data
,
plz_patterns
):
def
_
get_
coordinates
(
data
,
plz_patterns
):
geometries
=
[]
for
plz_pattern
in
plz_patterns
:
found
=
False
...
...
@@ -95,9 +95,9 @@ def get_plz(data, plz_patterns):
return
wkt_polygon
def
main
(
plzs
):
data
=
parse_data
()
get_plz
(
data
,
plzs
)
def
get_coordinates_by_zipcode
(
plzs
):
plz_shapes
=
_get_plz_shapes
()
return
_get_coordinates
(
plz_shapes
,
plzs
)
if
__name__
==
'__main__'
:
...
...
@@ -105,4 +105,4 @@ if __name__ == '__main__':
parser
.
add_argument
(
'plzs'
,
metavar
=
'PLZ'
,
type
=
str
,
nargs
=
'+'
,
help
=
'desired PLZs'
)
args
=
parser
.
parse_args
()
main
(
args
.
plzs
)
get_coordinates_by_zipcode
(
args
.
plzs
)
test_zipcode.py
0 → 100644
View file @
862ff084
import
unittest
import
get_coordinates_by_zipcode
class
TestClass
(
unittest
.
TestCase
):
def
test_method
(
self
):
self
.
assertEqual
(
'foo'
.
upper
(),
'FOO'
)
get_coordinates_by_zipcode
.
get_coordinates_by_zipcode
([
'70567'
])
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment