Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
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
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
513385cc
Commit
513385cc
authored
3 years ago
by
OndraRehounek
Committed by
jan.bednarik
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
working import for vysocina - handling several possible exceptions
parent
d50aa43b
No related branches found
No related tags found
2 merge requests
!442
Release
,
!432
Feature/majak imports
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
district/jekyll_import.py
+36
-8
36 additions, 8 deletions
district/jekyll_import.py
with
36 additions
and
8 deletions
district/jekyll_import.py
+
36
−
8
View file @
513385cc
...
...
@@ -57,6 +57,15 @@ class ImgProcessor(InlineProcessor):
image_obj
=
get_or_create_image
(
params
[
"
path
"
],
m
.
group
(
2
),
collection
=
collection
,
repo_name
=
""
)
if
not
image_obj
:
message_list
.
append
(
{
"
level
"
:
WARNING
,
"
text
"
:
"
Nenalezen obrázek {}
"
.
format
(
params
[
"
path
"
]),
}
)
return
None
,
m
.
start
(
0
),
m
.
end
(
0
)
el
.
attrib
[
"
id
"
]
=
str
(
image_obj
.
pk
)
return
el
,
m
.
start
(
0
),
m
.
end
(
0
)
...
...
@@ -90,13 +99,23 @@ def import_post(path, file_path, parent, title_suffix, dry_run, repo_name):
with
open
(
os
.
path
.
join
(
path
,
file_path
),
"
rt
"
)
as
f
:
r
=
re
.
split
(
r
"
^---\s*$
"
,
f
.
read
(),
maxsplit
=
3
,
flags
=
re
.
MULTILINE
)
try
:
meta
=
yaml
.
safe_load
(
r
[
1
])
except
ScannerError
:
message_list
.
append
(
{
"
level
"
:
ERROR
,
"
text
"
:
"
Nevalidní yaml pro {}
"
.
format
(
path
)}
)
return
None
,
False
md
=
r
[
2
]
html
=
html_md
.
convert
(
md
)
# meta_date = meta["date"]
# article_date = meta_date if isinstance(meta_date, date) else meta["date"].split()[0]
if
DistrictArticlePage
.
objects
.
filter
(
title
=
meta
[
"
title
"
]).
exists
():
for
article
in
DistrictArticlePage
.
objects
.
filter
(
title
=
meta
[
"
title
"
]):
if
article
.
date
==
parse_date
(
meta
[
"
date
"
].
split
()[
0
]):
#
if article.date == parse_date(meta["date"].split()[0]):
msg
=
"
Článek již existuje: %s
"
%
article
stdout
.
write
(
msg
)
message_list
.
append
({
"
level
"
:
INFO
,
"
text
"
:
msg
})
...
...
@@ -162,7 +181,7 @@ def get_path_and_repo_name(url: str, use_git: bool) -> (str, str):
return
download_repo_as_zip
(
url
)
def
get_or_create_image
(
path
,
file_path
,
collection
,
repo_name
):
def
get_or_create_image
(
path
,
file_path
,
collection
,
repo_name
)
->
Image
or
None
:
file_path
=
file_path
.
lstrip
(
"
/
"
)
if
Image
.
objects
.
filter
(
title
=
file_path
).
exists
():
return
Image
.
objects
.
filter
(
title
=
file_path
).
first
()
...
...
@@ -179,7 +198,16 @@ def get_or_create_image(path, file_path, collection, repo_name):
img_assets_folder
,
img_name
)
img_path
=
os
.
path
.
join
(
path
,
img_name
)
try
:
urllib
.
request
.
urlretrieve
(
img_url
,
img_path
)
except
(
HTTPError
,
UnicodeEncodeError
,
InvalidURL
):
message_list
.
append
(
{
"
level
"
:
WARNING
,
"
text
"
:
"
Nelze stáhout obrázek {}
"
.
format
(
img_url
),
}
)
return
None
file
=
ImageFile
(
open
(
img_path
,
"
rb
"
),
name
=
img_path
)
image
=
Image
(
title
=
file_path
,
file
=
file
,
collection
=
collection
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment