I need assistance about my code when I exucute it out is error or cannot alarm that sound .Note! This code is for appointement and want alarming about the opening of portal

import requests
from bs4 import BeautifulSoup
import time
from playsound import playsound

URL of the German Embassy Islamabad appointment page

APPOINTMENT_URL = ‘https://service2.diplo.de/rktermin/extern/choose_category.do?locationCode=isla&realmId=108&categoryId=1600’ # Replace with actual URL

Keyword or status that indicates the appointment is open

APPOINTMENT_OPEN_TEXT = “appointments open” # Update based on the actual text on the webpage

def check_appointment():
“”“Check if the appointment is available on the embassy website.”“”
try:
response = requests.get(APPOINTMENT_URL)
response.raise_for_status() # Raise an error for bad responses

    # Parse the webpage content
    soup = BeautifulSoup(response.content, 'html.parser')

    # Look for appointment status in the page's text (modify based on actual webpage structure)
    if "appointments open" in soup.get_text().lower():
        playsound('success.mp3')
    else:
        playsound('retry.mp3')

except requests.exceptions.RequestException as e:
    print(f"Error checking the website: {e}")
    return False

def main():
“”“Continuously monitor the embassy’s website.”“”
print(“Starting to monitor the appointment page…”)

while True:
    if check_appointment():
        break  # Stop checking once the appointment is open
    # Wait 15 second before the next check
    time.sleep(5)

if name == “main”:
main()

2 Likes