68 lines
2.0 KiB
Python
Executable File
68 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
import sys
|
|
|
|
# parse args
|
|
if len(sys.argv) != 4:
|
|
print(f"Usage: {sys.argv[0]} <P|R|ID> <Seriennummer> <Geburtsdatum>\nP: Personalausweis\nR: Reisepass\nID: eID-Karte", file=sys.stderr)
|
|
exit(1)
|
|
|
|
passauswahl = None
|
|
match sys.argv[1]:
|
|
case "P":
|
|
passauswahl = "B"
|
|
case "R":
|
|
passauswahl = "R"
|
|
case "ID":
|
|
passauswahl = "UB"
|
|
case other:
|
|
print(f"Invalid passauswahl: {other}. Valid options are: P, R, ID")
|
|
exit(2)
|
|
|
|
seriennummer = sys.argv[2]
|
|
geburtsdatum = sys.argv[3]
|
|
|
|
URL1 = "https://ausweisstatus.regioit.de/aachen"
|
|
URL2 = "https://ausweisstatus.regioit.de/antragsstatusausweis_regioit/statusrequest.jsf"
|
|
URL3 = "https://ausweisstatus.regioit.de/antragsstatusausweis_regioit/statusresponse.jsf"
|
|
|
|
# create session for requests to preserve cookies
|
|
session = requests.Session()
|
|
|
|
# get session cookie and javax viewstate
|
|
resp1 = session.get(URL1)
|
|
soup = BeautifulSoup(resp1.text, "html.parser")
|
|
viewstate = soup.find(id="javax.faces.ViewState")["value"]
|
|
|
|
if not viewstate:
|
|
print("Failed to determine session viewstate", file=sys.stderr)
|
|
exit(10)
|
|
|
|
# send post request with payload
|
|
headers = {
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
}
|
|
data = {
|
|
"antragsForm": "antragsForm",
|
|
"antragsForm:passauswahl": passauswahl, # B: perso, R: reisepass, UB: eid-karte
|
|
"antragsForm:seriennummer": seriennummer,
|
|
"antragsForm:geburtsdatum": geburtsdatum,
|
|
"antragsForm:j_id22": "Antragsstatus ermitteln",
|
|
"javax.faces.ViewState": viewstate,
|
|
}
|
|
session.post(URL2, headers=headers, data=data) # this returns 404 for some reason but works
|
|
|
|
# send get request to get current status
|
|
resp3 = session.get(URL3)
|
|
soup = BeautifulSoup(resp3.text, "html.parser")
|
|
status_div = soup.find(id="statusAnzeige")
|
|
if not status_div:
|
|
print("Could not determine status, please ensure the given serial number and birthday are valid", file=sys.stderr)
|
|
exit(3)
|
|
status = status_div.find("strong").get_text(strip=True)
|
|
print(status)
|
|
|
|
session.close()
|