Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Wuff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rushel Silvester
Wuff
Merge requests
!4
add: create_dog()
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
add: create_dog()
master
into
main
Overview
0
Commits
2
Pipelines
1
Changes
4
Merged
Rushel Silvester
requested to merge
master
into
main
2 years ago
Overview
0
Commits
2
Pipelines
1
Changes
4
Expand
add: pre-commit
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
590588d1
2 commits,
2 years ago
4 files
+
82
−
29
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/wuff.py
+
67
−
28
Options
import
requests
import
requests
import
csv
import
csv
import
argparse
import
argparse
import
random
import
shutil
import
pathlib
as
Path
URL
=
"
https://data.stadt-zuerich.ch/dataset/sid_stapo_hundenamen_od1002/download/KUL100OD1002.csv
"
DATA_URL
=
(
"
https://data.stadt-zuerich.ch/dataset/
"
"
sid_stapo_hundenamen_od1002/download/KUL100OD1002.csv
"
)
DOG_IMAGE_URL
=
"
https://random.dog/woof.json
"
def
get_parser
():
def
get_parser
():
para
=
argparse
.
ArgumentParser
()
para
=
argparse
.
ArgumentParser
()
para
.
add_argument
(
'
--year
'
,
action
=
'
store
'
,
default
=
'
2015
'
)
para
.
add_argument
(
"
-o
"
,
"
--output
"
,
help
=
"
Output file name
"
,
default
=
"
images
"
)
# parser = para.add_mutually_exclusive_group()
para
.
add_argument
(
"
--year
"
,
action
=
"
store
"
,
help
=
"
set search year
"
,
default
=
"
2015
"
)
para
.
add_argument
(
'
-find
'
,
nargs
=
'
?
'
)
# parser = para.add_mutually_exclusive_group()
para
.
add_argument
(
'
-create
'
,
nargs
=
'
?
'
)
para
.
add_argument
(
"
-find
"
,
help
=
"
find dog
"
,
nargs
=
"
?
"
)
para
.
add_argument
(
'
-stats
'
,
action
=
'
store_true
'
)
para
.
add_argument
(
"
-create
"
,
help
=
"
create new Dog
"
,
action
=
"
store_true
"
)
para
.
add_argument
(
"
-stats
"
,
help
=
"
show stat
"
,
action
=
"
store_true
"
)
return
para
return
para
def
show_stats
():
def
show_stats
(
dog_list
):
print
(
"
stats
"
)
print
(
"
stats
"
)
def
find_dog
(
arg
,
dog_list
):
for
dog
in
dog_list
:
if
dog
[
"
StichtagDatJahr
"
]
==
arg
.
year
and
dog
[
"
HundenameText
"
]
==
arg
.
find
:
print
(
"
name:
"
+
dog
[
"
HundenameText
"
])
print
(
"
birth year:
"
+
dog
[
"
GebDatHundJahr
"
])
print
(
"
sex:
"
+
dog
[
"
SexHundLang
"
]
+
"
,
\n
"
)
def
get_image_url
(
url
):
response
=
requests
.
get
(
url
)
res
=
response
.
json
()
return
res
[
"
url
"
]
def
find_dog
(
arg
):
list
=
requestHandler
(
URL
)
for
l
in
list
:
if
(
l
[
'
\ufeff
"
StichtagDatJahr
"'
]
==
arg
.
year
and
l
[
'
HundenameText
'
]
==
arg
.
find
):
print
(
"
name:
"
+
l
[
'
HundenameText
'
])
print
(
"
birth year:
"
+
l
[
'
GebDatHundJahr
'
])
print
(
"
sex:
"
+
l
[
'
SexHundLang
'
]
+
"
,
\n
"
)
def
create_dog
(
create
):
def
create_image
(
path
):
print
(
create
)
image_url
=
get_image_url
(
DOG_IMAGE_URL
)
end
=
image_url
.
split
(
"
.
"
)[
-
1
]
response
=
requests
.
get
(
image_url
,
stream
=
True
)
with
open
(
path
.
with_suffix
(
"
.
"
+
end
),
"
wb
"
)
as
out_file
:
shutil
.
copyfileobj
(
response
.
raw
,
out_file
)
print
(
f
"
The image of the new dog can be found here:
"
f
"
{
path
.
with_suffix
(
'
.
'
+
end
)
}
"
)
def
create_dog
(
path
,
dog_list
):
path
=
Path
.
Path
(
path
)
hunde_name
=
dog_list
[
random
.
randint
(
0
,
len
(
dog_list
))][
"
HundenameText
"
]
geb_date
=
dog_list
[
random
.
randint
(
0
,
len
(
dog_list
))][
"
GebDatHundJahr
"
]
sex_hund
=
random
.
choice
([
"
Male
"
,
"
Female
"
])
path
=
path
/
f
"
{
hunde_name
.
replace
(
'
'
,
'
_
'
)
}
_
{
geb_date
}
"
print
(
"
Here
'
s your new dog!
"
)
print
(
"
Name:
"
+
hunde_name
)
print
(
"
Yirth year:
"
+
geb_date
)
print
(
"
Sex: :
"
+
sex_hund
)
create_image
(
path
)
def
parser_handler
(
args
):
def
parser_handler
(
args
,
dog_list
):
if
args
.
stats
:
if
args
.
stats
:
show_stats
()
show_stats
(
dog_list
)
elif
(
args
.
find
is
not
None
):
elif
args
.
find
is
not
None
:
find_dog
(
args
)
find_dog
(
args
,
dog_list
)
elif
(
args
.
create
is
not
None
):
elif
args
.
create
:
create_dog
(
args
)
create_dog
(
args
.
output
,
dog_list
)
def
requestHandler
(
url
):
def
requestHandler
(
url
):
with
requests
.
Session
()
as
s
:
with
requests
.
Session
()
as
s
:
download
=
s
.
get
(
url
)
download
=
s
.
get
(
url
)
decoded_content
=
download
.
content
.
decode
(
'
utf-8
'
)
# download.encoding = "utf-8-sig"
cr
=
csv
.
DictReader
(
decoded_content
.
splitlines
(),
delimiter
=
'
,
'
)
decoded_content
=
download
.
content
.
decode
(
"
utf-8-sig
"
)
cr
=
csv
.
DictReader
(
decoded_content
.
splitlines
(),
delimiter
=
"
,
"
)
my_list
=
list
(
cr
)
my_list
=
list
(
cr
)
return
my_list
return
my_list
def
main
(
args
=
None
):
def
main
(
args
=
None
):
parser
=
get_parser
()
parser
=
get_parser
()
parsed
=
parser
.
parse_args
([
"
-find
"
,
"
Bob
"
,
"
--year
"
,
"
2020
"
])
parsed
=
parser
.
parse_args
([
"
-create
"
])
#parsed = get_parser().parse_args(args)
# parsed = get_parser().parse_args(args)
parser_handler
(
parsed
)
dog_list
=
requestHandler
(
DATA_URL
)
if
__name__
==
'
__main__
'
:
parser_handler
(
parsed
,
dog_list
)
if
__name__
==
"
__main__
"
:
main
()
main
()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
Loading