From 1edda762d08cd2cfc068ce0b25839813be676cd8 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 3 Jan 2024 15:04:10 +0100 Subject: [PATCH] Current version --- README.md | 6 ++++++ bot.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 README.md create mode 100644 bot.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ea5cf4 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Berufsinfomat Python Wrapper + +This is just a simple Python script allowing you to access the [AMS Berufsinfomat](https://www.ams.at/arbeitsuchende/aus-und-weiterbildung/berufsinformationen/berufsinformation/berufsinfomat?open=berufsinfomat) +from the command line instead of using the web interface. + +Do with that information whatever you will. \ No newline at end of file diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..d123e45 --- /dev/null +++ b/bot.py @@ -0,0 +1,41 @@ +import requests +import random +import string +import html +import json +from urllib.request import Request, urlopen + +def send_question_to_ams(question, chat_session_id): + url = "https://berufsinfomat.prod.portal.ams.at/client/6453a57358480fb76ddc0a43/send_question" + + headers = { + "Content-Type": "application/json", + "User-Agent": "" + } + + data = json.dumps({ + "question": question, + "chat_session_id": chat_session_id + }).encode("utf-8") + + req = Request(url, headers=headers, data=data) + response = urlopen(req) + + text = html.unescape(response.read().decode()).replace("
", "\n").replace("
", "\n").replace("
", "\n") + return text.split("===")[-1].strip() + +def main(): + chat_session_id = "".join([random.SystemRandom().choice(string.hexdigits) for _ in range(32)]) + print("Welcome to the AMS Berufsinfomat interactive conversation!") + print("Type 'exit' to end the conversation.\n") + + while True: + question = input("> ") + if question.lower() == "exit": + print("Ending conversation.") + break + response = send_question_to_ams(question, chat_session_id) + print(response + "\n") + +if __name__ == "__main__": + main() \ No newline at end of file