Current version
This commit is contained in:
commit
1edda762d0
2 changed files with 47 additions and 0 deletions
6
README.md
Normal file
6
README.md
Normal file
|
@ -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.
|
41
bot.py
Normal file
41
bot.py
Normal file
|
@ -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("<br>", "\n").replace("<br/>", "\n").replace("<br />", "\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()
|
Loading…
Reference in a new issue