-1

I am writing a script that notifies me when available slots exists using the website API Here is the code :

import requests
import datetime
import time
import math


URL = "API"

header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'}
    
def available_slots():
    counter = 0
    result = requests.get(URL, headers=header)
    response_json = result.json()
    data = response_json["2022-12-08"]
    for each in data:
        if((each["available"] == True)):
            counter += 1
            print(each["name"])
            return True
    if(counter == 0):
        print("No Available Slots")
        return False

and here is a pic of the website api :

api

I was expecting for the script to run but it doesnt return any value or errors. sorry I am a newbie.

Azhar Khan
  • 3,829
  • 11
  • 26
  • 32

1 Answers1

0

As @Abraham Tugalov commented, you need to call your function. Add the following to the end of your script, at the same indentation level as your imports (which is to say, no indentation):

if __name__ == "__main__":
    available_slots()

Further information: What-does-if-name-main-do?

bigkeefer
  • 576
  • 1
  • 6
  • 13