Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
C
crawler
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Project - Tarifs Crawler & API
crawler
Commits
088d522c
Commit
088d522c
authored
May 12, 2025
by
Marco Schmiedel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
c72b60bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
EeccxRouter.py
routes/EeccxRouter.py
+11
-10
No files found.
routes/EeccxRouter.py
View file @
088d522c
...
@@ -18,7 +18,7 @@ from models.base_base import BaseBase
...
@@ -18,7 +18,7 @@ from models.base_base import BaseBase
from
models.option_opti
import
OptionOpti
from
models.option_opti
import
OptionOpti
from
config.MauiConfig
import
EECCX_TOKEN_URL
,
EECCX_API_URL
,
EECCX_CLIENT_ID
,
EECCX_CLIENT_SECRET
,
EECCX_CF_CLIENT_ID
,
EECCX_CF_CLIENT_SECRET
,
EECCX_HDL_NR
,
EECCX_PROV_HDL_NR
from
config.MauiConfig
import
EECCX_TOKEN_URL
,
EECCX_API_URL
,
EECCX_CLIENT_ID
,
EECCX_CLIENT_SECRET
,
EECCX_CF_CLIENT_ID
,
EECCX_CF_CLIENT_SECRET
,
EECCX_HDL_NR
,
EECCX_PROV_HDL_NR
# A warning is disabled so self
‑
signed certificate usage does not flood the log in development environments.
# A warning is disabled so self
-
signed certificate usage does not flood the log in development environments.
urllib3
.
disable_warnings
(
urllib3
.
exceptions
.
InsecureRequestWarning
)
urllib3
.
disable_warnings
(
urllib3
.
exceptions
.
InsecureRequestWarning
)
# The constant TOKEN_URL stores the identity provider endpoint used for OAuth authentication.
# The constant TOKEN_URL stores the identity provider endpoint used for OAuth authentication.
...
@@ -27,7 +27,7 @@ TOKEN_URL = EECCX_TOKEN_URL
...
@@ -27,7 +27,7 @@ TOKEN_URL = EECCX_TOKEN_URL
# The constant API_URL stores the partner API endpoint that generates the PDF.
# The constant API_URL stores the partner API endpoint that generates the PDF.
API_URL
=
EECCX_API_URL
API_URL
=
EECCX_API_URL
# The constant CLIENT_ID stores the OAuth client identifier for the back
‑
end application.
# The constant CLIENT_ID stores the OAuth client identifier for the back
-
end application.
CLIENT_ID
=
EECCX_CLIENT_ID
CLIENT_ID
=
EECCX_CLIENT_ID
# The constant CLIENT_SECRET stores the OAuth client secret matching the client identifier.
# The constant CLIENT_SECRET stores the OAuth client secret matching the client identifier.
...
@@ -59,22 +59,23 @@ def _json_error(message: str, status_code: int = 502) -> Response:
...
@@ -59,22 +59,23 @@ def _json_error(message: str, status_code: int = 502) -> Response:
# A JSON payload is assembled with status "ERROR" and the provided message.
# A JSON payload is assembled with status "ERROR" and the provided message.
payload
=
json
.
dumps
({
"status"
:
"ERROR"
,
"message"
:
message
},
ensure_ascii
=
False
)
payload
=
json
.
dumps
({
"status"
:
"ERROR"
,
"message"
:
message
},
ensure_ascii
=
False
)
return
Response
(
payload
,
status
=
status_code
,
mimetype
=
"application/json"
)
# Always return HTTP 200 to prevent Cloudflare from replacing the response with its own 5XX page.
return
Response
(
payload
,
status
=
200
,
mimetype
=
"application/json"
)
# The function extracts the option identifiers from the query string and normalises comma
‑
separated values into a list.
# The function extracts the option identifiers from the query string and normalises comma
-
separated values into a list.
def
_extract_options
()
->
List
[
str
]:
def
_extract_options
()
->
List
[
str
]:
# The raw option list is read from the query argument list to handle multiple "options" parameters.
# The raw option list is read from the query argument list to handle multiple "options" parameters.
raw
=
request
.
args
.
getlist
(
"options"
)
raw
=
request
.
args
.
getlist
(
"options"
)
# The following conditional branch handles the special case in which a single comma
‑
separated value has been supplied instead of repeated parameters.
# The following conditional branch handles the special case in which a single comma
-
separated value has been supplied instead of repeated parameters.
if
len
(
raw
)
==
1
and
","
in
raw
[
0
]:
if
len
(
raw
)
==
1
and
","
in
raw
[
0
]:
# The value is split on commas and stripped so empty strings are removed from the final list.
# The value is split on commas and stripped so empty strings are removed from the final list.
return
[
opt
.
strip
()
for
opt
in
raw
[
0
]
.
split
(
","
)
if
opt
.
strip
()]
return
[
opt
.
strip
()
for
opt
in
raw
[
0
]
.
split
(
","
)
if
opt
.
strip
()]
return
[
opt
for
opt
in
raw
if
opt
]
return
[
opt
for
opt
in
raw
if
opt
]
# The function builds a unique hash from tarif_id, the option list, and the current timestamp so the uploaded PDF file name is collision
‑
free.
# The function builds a unique hash from tarif_id, the option list, and the current timestamp so the uploaded PDF file name is collision
-
free.
def
_hash_id_options
(
tarif_id
:
str
,
options
:
List
[
str
])
->
str
:
def
_hash_id_options
(
tarif_id
:
str
,
options
:
List
[
str
])
->
str
:
# The key string concatenates tarif_id, the sorted option list, and the current Unix timestamp.
# The key string concatenates tarif_id, the sorted option list, and the current Unix timestamp.
...
@@ -118,7 +119,7 @@ def _get_token() -> Tuple[str | None, str | None]:
...
@@ -118,7 +119,7 @@ def _get_token() -> Tuple[str | None, str | None]:
# The function assembles the partner API payload, performs the HTTP PUT request, and returns either the JSON result or an error message.
# The function assembles the partner API payload, performs the HTTP PUT request, and returns either the JSON result or an error message.
def
_partner_api
(
token
:
str
,
tarif_id
:
str
,
options
:
List
[
str
])
->
Tuple
[
dict
|
None
,
str
|
None
]:
def
_partner_api
(
token
:
str
,
tarif_id
:
str
,
options
:
List
[
str
])
->
Tuple
[
dict
|
None
,
str
|
None
]:
# The headers dictionary includes OAuth, Cloudflare, and content
‑
type information required by the partner API.
# The headers dictionary includes OAuth, Cloudflare, and content
-
type information required by the partner API.
headers
=
{
headers
=
{
"Authorization"
:
f
"Bearer {token}"
,
"Authorization"
:
f
"Bearer {token}"
,
"CF-Access-Client-Id"
:
CF_CLIENT_ID
,
"CF-Access-Client-Id"
:
CF_CLIENT_ID
,
...
@@ -244,7 +245,7 @@ def _partner_api(token: str, tarif_id: str, options: List[str]) -> Tuple[dict |
...
@@ -244,7 +245,7 @@ def _partner_api(token: str, tarif_id: str, options: List[str]) -> Tuple[dict |
# An error tuple is returned when the response is not valid JSON.
# An error tuple is returned when the response is not valid JSON.
return
None
,
"Antwort der Partner-API ist kein JSON."
return
None
,
"Antwort der Partner-API ist kein JSON."
# The err_val variable is inspected for API
‑level error information that must be mapped to a user‑
friendly string.
# The err_val variable is inspected for API
-level error information that must be mapped to a user-
friendly string.
err_val
=
data
.
get
(
"error"
)
err_val
=
data
.
get
(
"error"
)
# The following conditional branch returns an error tuple when the API embedded error information in its JSON body.
# The following conditional branch returns an error tuple when the API embedded error information in its JSON body.
...
@@ -310,7 +311,7 @@ def eeccx_pdf(tarif_id: str):
...
@@ -310,7 +311,7 @@ def eeccx_pdf(tarif_id: str):
if
err
:
if
err
:
return
_json_error
(
err
,
502
)
return
_json_error
(
err
,
502
)
# A unique hash is generated so the temporary file and the S3 object name are collision
‑
free.
# A unique hash is generated so the temporary file and the S3 object name are collision
-
free.
hash_name
=
_hash_id_options
(
tarif_id
,
options
)
hash_name
=
_hash_id_options
(
tarif_id
,
options
)
# A temporary file is opened so the PDF can be written to disk for uploading.
# A temporary file is opened so the PDF can be written to disk for uploading.
...
@@ -329,4 +330,4 @@ def eeccx_pdf(tarif_id: str):
...
@@ -329,4 +330,4 @@ def eeccx_pdf(tarif_id: str):
# A JSON response is returned containing the public URL of the uploaded PDF.
# A JSON response is returned containing the public URL of the uploaded PDF.
payload
=
json
.
dumps
({
"url"
:
url
},
ensure_ascii
=
False
)
payload
=
json
.
dumps
({
"url"
:
url
},
ensure_ascii
=
False
)
return
Response
(
payload
,
status
=
200
,
mimetype
=
"application/json"
)
return
Response
(
payload
,
status
=
200
,
mimetype
=
"application/json"
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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