organic: Enhance external apis

This commit is contained in:
2025-12-22 16:56:23 +01:00
parent 551ddd3c11
commit 0cd3b3de8e
10 changed files with 350 additions and 110 deletions

View File

@@ -18,23 +18,34 @@ def main() -> None:
args = parser.parse_args()
s = requests.Session()
r = s.get(f'{URL}?menu_sid=5002')
uri = ACTION_RE.findall(r.text)[0]
while True:
try:
r = s.get(f'{URL}?menu_sid=5002')
uri = ACTION_RE.findall(r.text)[0]
break
except IndexError:
pass
hidden = {m[1]: m[2] for m in HIDDEN_RE.finditer(r.text)}
r = s.post(f'{BASE_URL}{uri}', data={
'PartnerCertSearchForm:pcs_seqidall': args.cert_nr,
'PartnerCertSearchForm:button_search': 'Suche starten...',
'PartnerCertSearchForm_SUBMIT': '1',
'javax.faces.ViewState': hidden['javax.faces.ViewState'],
})
while True:
r = s.post(f'{BASE_URL}{uri}', data={
'PartnerCertSearchForm:pcs_seqidall': args.cert_nr,
'PartnerCertSearchForm:button_search': 'Suche starten...',
'PartnerCertSearchForm_SUBMIT': '1',
'javax.faces.ViewState': hidden['javax.faces.ViewState'],
})
p1 = r.text.find(f'>{args.cert_nr}<')
p2 = r.text.find('id="', p1)
p3 = r.text.find('"', p2 + 4)
if p1 == -1 or p2 == -1 or p3 == -1:
exit(1)
id = r.text[p2 + 4:p3]
if 'class="msg_error"' in r.text:
print(f'404', file=sys.stderr)
exit(1)
p1 = r.text.find(f'>{args.cert_nr}<')
p2 = r.text.find('id="', p1)
p3 = r.text.find('"', p2 + 4)
if p1 == -1 or p2 == -1 or p3 == -1:
continue
id = r.text[p2 + 4:p3]
break
r = s.post(f'{BASE_URL}{uri}', data={
'PartnerCertSearchForm:_idcl': id,

View File

@@ -33,8 +33,13 @@ def main() -> None:
query = {'PartnerCertSearchForm:pcs_' + q.split('=', 1)[0]: urllib.parse.unquote(q.split('=', 1)[-1]) for q in args.query.split('&')}
s = requests.Session()
r = s.get(f'{URL}?menu_sid=5002')
uri = ACTION_RE.findall(r.text)[0]
while True:
try:
r = s.get(f'{URL}?menu_sid=5002')
uri = ACTION_RE.findall(r.text)[0]
break
except IndexError:
pass
hidden = {m[1]: m[2] for m in HIDDEN_RE.finditer(r.text)}
r = s.post(f'{BASE_URL}{uri}', data={
@@ -69,7 +74,7 @@ def main() -> None:
'validTo': '-'.join(reversed(srow[2].split('-'))),
'type': srow[3],
'attachmentSid': srow[4],
'url': f'https://elwig.at/organic/external/bioqs/attachments/{urllib.parse.quote(srow[0])}',
'pdfUrl': f'https://elwig.at/organic/external/bioqs/attachments/{urllib.parse.quote(srow[0])}',
})
if not first:
print(',', flush=True)
@@ -80,10 +85,10 @@ def main() -> None:
'postalCode': row[3],
'city': row[4],
'address': row[5],
'autorityName': meta['Kontrollstelle'],
'authority': {'name': meta['Kontrollstelle']},
'productGroups': meta['Bereiche'],
'certificates': certificates,
}, ensure_ascii=False), end='')
}, ensure_ascii=False, separators=(',',':')), end='')
first = False
print('\n]')

View File

@@ -3,30 +3,38 @@
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 405');
header('Content-Length: 0');
header('Content-Length: 56');
header('Allow: GET, HEAD');
echo "{\"error\":\"method not allowed\",\"allow\":[\"GET\",\"HEAD\"]}\n";
exit;
}
$info = $_SERVER['PATH_INFO'];
if ($info === '') {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 404');
header('Content-Length: 0');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}
$certId = substr($info, 1);
$file = tmpfile();
if (!$file) {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 500');
header('Content-Length: 0');
header('Content-Length: 34');
echo "{\"error\":\"internal server error\"}\n";
exit;
}
$filename = stream_get_meta_data($file)['uri'];
if (($pdfName = exec("python3 .attachment.py " . escapeshellarg($certId) . " 2>&1 > $filename ")) === false) {
header('Status: 500');
header('Content-Length: 0');
if (($pdfName = exec("python3 .attachment.py " . escapeshellarg($certId) . " 2>&1 > $filename ")) === "404") {
header('Content-Type: application/json; charset=UTF-8');
header('Status: 404');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}

View File

@@ -1,18 +1,21 @@
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=UTF-8');
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
header('Status: 405');
header('Content-Length: 0');
header('Content-Length: 56');
header('Allow: GET, HEAD');
echo "{\"error\":\"method not allowed\",\"allow\":[\"GET\",\"HEAD\"]}\n";
exit;
}
$info = $_SERVER['PATH_INFO'];
if ($info !== '') {
header('Status: 404');
header('Content-Length: 0');
header('Content-Length: 22');
echo "{\"error\":\"not found\"}\n";
exit;
}
@@ -36,8 +39,6 @@ if (isset($_GET['lfbisNr'])) {
$query[] = 'lfbis=' . urlencode($_GET['lfbisNr']);
}
header('Content-Type: application/json; charset=UTF-8');
echo "{\"data\":";
passthru("python3 .operators.py " . escapeshellarg(implode('&', $query)));
echo "}\n";