Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pad-Initiator
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
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
Logistik
pad-Initiator
Commits
1274fefe
Commit
1274fefe
authored
2 months ago
by
Tim Neumann
Browse files
Options
Downloads
Patches
Plain Diff
fix: Fix error handling and clean up
parent
23acd203
No related branches found
Branches containing commit
No related tags found
1 merge request
!11
Pad downloader
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pad_downloader.py
+4
-1
4 additions, 1 deletion
pad_downloader.py
pad_initiator.py
+4
-2
4 additions, 2 deletions
pad_initiator.py
with
8 additions
and
3 deletions
pad_downloader.py
+
4
−
1
View file @
1274fefe
#!/usr/bin/env python3
from
typing
import
Dict
,
Optional
,
Tuple
,
Generator
from
typing
import
Dict
,
Optional
from
os
import
environ
,
path
,
getcwd
,
makedirs
from
dotenv
import
load_dotenv
...
...
@@ -37,6 +37,7 @@ def _download_uploaded_file(
r
:
requests
.
Response
=
requests
.
get
(
urlunparse
(
file
),
headers
=
headers
,
cookies
=
cookies
)
if
not
r
.
ok
:
print
(
f
"
Failed to download file
{
file
}
. Status:
{
r
.
status_code
}
. Response:
{
r
.
content
.
decode
(
'
utf-8
'
)
}
"
)
return
file_name
=
file
.
path
.
split
(
"
/
"
)[
-
1
]
outfile
=
outdir
+
"
/uploads/
"
+
file_name
...
...
@@ -72,7 +73,9 @@ def _download_pad_recursive(
r
:
requests
.
Response
=
requests
.
get
(
urlunparse
(
request_url
),
headers
=
headers
,
cookies
=
cookies
)
if
not
r
.
ok
:
print
(
f
"
Failed to download pad
{
note
}
. Status:
{
r
.
status_code
}
. Response:
{
r
.
content
.
decode
(
'
utf-8
'
)
}
"
)
return
if
not
r
.
headers
[
"
Content-Type
"
].
startswith
(
"
text/markdown;
"
):
print
(
f
"
Pad
{
note
}
has wrong content type:
{
r
.
headers
[
'
Content-Type
'
]
}
.
"
)
return
response_content
=
r
.
content
...
...
This diff is collapsed.
Click to expand it.
pad_initiator.py
+
4
−
2
View file @
1274fefe
#!/usr/bin/env python3
from
typing
import
List
,
Dict
,
Optional
,
Tuple
,
Iterable
from
typing
import
List
,
Dict
,
Optional
,
Iterable
from
jinja2
import
Template
,
StrictUndefined
...
...
@@ -112,10 +112,12 @@ def initPads(files: List[str],
r
:
requests
.
Response
=
requests
.
post
(
url_for_this_file
,
headers
=
headers
,
cookies
=
cookies
,
data
=
pad_content
.
encode
(
'
utf-8
'
),
allow_redirects
=
False
)
if
not
r
.
ok
:
print
(
f
"
Failed to create pad for
{
file_name
}
. Status:
{
r
.
status_code
}
. Response:
{
r
.
content
.
decode
(
'
utf-8
'
)
}
"
)
continue
if
not
r
.
is_redirect
:
print
(
f
"
Failed to create pad for
{
file_name
}
. Response was not a well formed redirect. Response:
{
r
.
content
.
decode
(
'
utf-8
'
)
}
"
)
continue
created_page_link
=
r
.
next
.
url
created_page_link
:
str
=
r
.
next
.
url
# type: ignore
all_the_links
[
file_name
]
=
created_page_link
...
...
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