mbosse99's picture
upadate with time zones added
e8dca67 verified
raw
history blame
6.9 kB
import requests
import json
import os
import streamlit as st
from datetime import datetime, timedelta
from ParamClasses import CreateParams
from dotenv import load_dotenv
load_dotenv()
def create_meeting(input_params: CreateParams) -> dict:
try:
url = f"{os.environ.get('BASE_API')}/api/create-appointment"
response = requests.post(url=url,data=input_params)
response.raise_for_status()
return response.json()
except Exception as e:
print(f"Fehler beim erstellen des Termins: {str(e)}")
st.error("Something went wrong, please contact the site admin.", icon="🚨")
def get_summary(input_params) -> dict:
try:
url = f"{os.environ.get('BASE_API')}/api/create-interview-summary"
response = requests.post(url=url,data=input_params)
response.raise_for_status()
return response.json()
except Exception as e:
print(f"Fehler beim erstellen des Termins: {str(e)}")
st.error(f"Something went wrong: {str(e)}", icon="🚨")
def adjust_datetime(original_datetime_str, offset_option):
# Konvertiere den originalen DateTime-String in ein datetime-Objekt
original_datetime = datetime.strptime(original_datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ")
# Überprüfe das Vorzeichen im Offset-String
if offset_option.startswith('+'):
# Wenn das Vorzeichen ein Pluszeichen ist, negiere den Offset
offset_option = '-' + offset_option[1:]
elif offset_option.startswith('-'):
offset_option = '+' + offset_option[1:]
else:
# Wenn kein Vorzeichen vorhanden ist, füge ein Minuszeichen hinzu
offset_option = '' + offset_option
# Konvertiere die Offset-Option von String zu integer
offset_hours = int(offset_option)
# Erzeuge ein timedelta-Objekt mit dem entsprechenden Offset
offset_delta = timedelta(hours=offset_hours)
# Passe das ursprüngliche datetime-Objekt an
adjusted_datetime = original_datetime + offset_delta
# Formatieren und zurückgeben
adjusted_datetime_str = adjusted_datetime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
return adjusted_datetime_str
if "appointment_response" not in st.session_state:
st.session_state["appointment_response"] = None
if "subject_input" not in st.session_state:
st.session_state["subject_input"] = None
col1, col2 = st.columns([2, 1])
col1.title("Appointment Tool")
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
st.write("Please enter the date, time and duration for the appointment to be created.")
selected_date = st.date_input("Date of the appointment",format="DD/MM/YYYY")
now = datetime.now()
rounded_now = now + timedelta(minutes=30 - now.minute % 30)
selected_time = st.time_input("Starting time of the appointment", value=rounded_now)
time_zone = st.selectbox("Please select your time zone (based on UTC time)",options=["+10","+9","+8","+7","+6","+5","+4","+3","+2","+1","0","-1","-2","-3","-4","-5","-6","-7","-8","-9","-10"],index=10, key="time_option")
selected_duration = st.select_slider("Duration of the appointment in minutes",[15,30,45,60],value=30)
subject_input = st.text_input("Enter the subject of the meeting")
recruiter_mail = st.text_input("Please enter the mail of the recruiter", key="recruiter_mail")
client_mail = st.text_input("Please enter the mail of the client", key="client_mail")
candidate_mail = st.text_input("Please enter the mail of the candidate", key="candidate_mail")
if not st.session_state["appointment_response"]:
if st.button("Create appointment") or st.session_state["appointment_response"]:
print("nach button appointment")
if subject_input:
start_date_utc_str = datetime.strptime(str(selected_date)+" "+str(selected_time),"%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%dT%H:%M:%S.%fZ")
print(start_date_utc_str)
start_date_str = adjust_datetime(start_date_utc_str, st.session_state["time_option"])
print(start_date_str)
end_date = datetime.strptime(str(selected_date)+" "+str(selected_time),"%Y-%m-%d %H:%M:%S") + timedelta(minutes=selected_duration)
end_date_utc_str = end_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
end_date_str = adjust_datetime(end_date_utc_str, st.session_state["time_option"])
with st.spinner("Creating the appointment..."):
request_params = json.dumps({
"appointment": {
"start_time": start_date_str,
"end_time": end_date_str
},
"subject": subject_input,
"recruiter": {
"email": st.session_state["recruiter_mail"],
"name": st.session_state["recruiter_mail"]
},
"client": {
"email": st.session_state["client_mail"],
"name": st.session_state["client_mail"]
},
"candidate": {
"email": st.session_state["candidate_mail"],
"name": st.session_state["candidate_mail"]
}
})
appointment_response = create_meeting(request_params)
# appointment_response = False
# st.write(appointment_response)
if appointment_response:
st.success("The appointment was created correctly.")
st.write(appointment_response["calendar_event"]["onlineMeeting"]["joinUrl"])
st.info("Once you have attended the meeting and it has ended, please wait about 5 minutes before requesting the meeting recording as it will take time to become available ", icon="ℹ️")
st.session_state["appointment_response"] = appointment_response
st.session_state["subject_input"] = subject_input
if st.button("Create Interview Summary"):
print("please")
st.rerun()
# print("nach btn summary")
# with st.spinner("Creating the summary..."):
# summary_response = get_summary({"interview_subject": subject_input})
# if summary_response:
# st.write(summary_response)
else:
st.warning("Please enter the subject of the meeting")
else:
with st.spinner("Creating the summary..."):
print(st.session_state["subject_input"])
print(isinstance(st.session_state["subject_input"],str))
print("bis hierhin gekommen")
summary_response = get_summary(json.dumps({"join_url": st.session_state["appointment_response"]["calendar_event"]["onlineMeeting"]["joinUrl"]}))
st.write(summary_response)