#import gradio as gr import json from datetime import datetime import pytz class TimeSlot: def __init__(self, payload): self.payload = payload def __repr__(self): return f"TimeSlot({self.start_time}, {self.end_time})" def get_times(self): python_dict = json.loads(self.payload) # Extract the keys (dates) from the dictionary result = "" for date, slots in python_dict['slots'].items(): # print(f"Available time slots on {date}:") result += f"Available time slots on {date}: " # Extract the time slots for each date for slot in slots: # Convert the time string to a datetime object time_str = slot['time'] # Convert the time string to a datetime object dt = datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc) localDatetime = dt.astimezone(pytz.timezone('America/Sao_Paulo')) timeslot = localDatetime.strftime("%H:%M") # print(f"{timeslot}", end=", ") result = f"{result}{timeslot}, " # print() # Print a newline after each date's slots result += "\n" return result pl = '{"slots":{"2025-05-19":[{"time":"2025-05-19T16:00:00.000Z"},{"time":"2025-05-19T17:00:00.000Z"},{"time":"2025-05-19T18:00:00.000Z"},{"time":"2025-05-19T19:00:00.000Z"}],"2025-05-20":[{"time":"2025-05-20T13:00:00.000Z"},{"time":"2025-05-20T14:00:00.000Z"},{"time":"2025-05-20T15:00:00.000Z"},{"time":"2025-05-20T16:00:00.000Z"},{"time":"2025-05-20T17:00:00.000Z"},{"time":"2025-05-20T18:00:00.000Z"},{"time":"2025-05-20T19:00:00.000Z"}],"2025-05-21":[{"time":"2025-05-21T12:00:00.000Z"},{"time":"2025-05-21T13:00:00.000Z"},{"time":"2025-05-21T14:00:00.000Z"},{"time":"2025-05-21T15:00:00.000Z"},{"time":"2025-05-21T16:00:00.000Z"},{"time":"2025-05-21T17:00:00.000Z"},{"time":"2025-05-21T18:00:00.000Z"},{"time":"2025-05-21T19:00:00.000Z"}],"2025-05-22":[{"time":"2025-05-22T12:00:00.000Z"},{"time":"2025-05-22T13:00:00.000Z"},{"time":"2025-05-22T14:00:00.000Z"},{"time":"2025-05-22T15:00:00.000Z"},{"time":"2025-05-22T16:00:00.000Z"},{"time":"2025-05-22T17:00:00.000Z"},{"time":"2025-05-22T18:00:00.000Z"},{"time":"2025-05-22T19:00:00.000Z"}],"2025-05-23":[{"time":"2025-05-23T12:00:00.000Z"},{"time":"2025-05-23T13:00:00.000Z"},{"time":"2025-05-23T14:00:00.000Z"},{"time":"2025-05-23T15:00:00.000Z"},{"time":"2025-05-23T16:00:00.000Z"},{"time":"2025-05-23T17:00:00.000Z"},{"time":"2025-05-23T18:00:00.000Z"},{"time":"2025-05-23T19:00:00.000Z"}],"2025-05-26":[{"time":"2025-05-26T12:00:00.000Z"},{"time":"2025-05-26T13:00:00.000Z"},{"time":"2025-05-26T14:00:00.000Z"},{"time":"2025-05-26T15:00:00.000Z"},{"time":"2025-05-26T16:00:00.000Z"},{"time":"2025-05-26T17:00:00.000Z"},{"time":"2025-05-26T18:00:00.000Z"},{"time":"2025-05-26T19:00:00.000Z"}],"2025-05-27":[{"time":"2025-05-27T12:00:00.000Z"},{"time":"2025-05-27T13:00:00.000Z"},{"time":"2025-05-27T14:00:00.000Z"},{"time":"2025-05-27T15:00:00.000Z"},{"time":"2025-05-27T16:00:00.000Z"},{"time":"2025-05-27T17:00:00.000Z"},{"time":"2025-05-27T18:00:00.000Z"},{"time":"2025-05-27T19:00:00.000Z"}],"2025-05-28":[{"time":"2025-05-28T12:00:00.000Z"},{"time":"2025-05-28T13:00:00.000Z"},{"time":"2025-05-28T14:00:00.000Z"},{"time":"2025-05-28T15:00:00.000Z"},{"time":"2025-05-28T16:00:00.000Z"},{"time":"2025-05-28T17:00:00.000Z"},{"time":"2025-05-28T18:00:00.000Z"},{"time":"2025-05-28T19:00:00.000Z"}],"2025-05-29":[{"time":"2025-05-29T12:00:00.000Z"},{"time":"2025-05-29T13:00:00.000Z"},{"time":"2025-05-29T14:00:00.000Z"},{"time":"2025-05-29T15:00:00.000Z"},{"time":"2025-05-29T16:00:00.000Z"},{"time":"2025-05-29T17:00:00.000Z"},{"time":"2025-05-29T18:00:00.000Z"},{"time":"2025-05-29T19:00:00.000Z"}],"2025-05-30":[{"time":"2025-05-30T12:00:00.000Z"},{"time":"2025-05-30T13:00:00.000Z"},{"time":"2025-05-30T14:00:00.000Z"},{"time":"2025-05-30T15:00:00.000Z"},{"time":"2025-05-30T16:00:00.000Z"},{"time":"2025-05-30T17:00:00.000Z"},{"time":"2025-05-30T18:00:00.000Z"},{"time":"2025-05-30T19:00:00.000Z"}],"2025-06-02":[{"time":"2025-06-02T12:00:00.000Z"},{"time":"2025-06-02T13:00:00.000Z"},{"time":"2025-06-02T14:00:00.000Z"},{"time":"2025-06-02T15:00:00.000Z"},{"time":"2025-06-02T16:00:00.000Z"},{"time":"2025-06-02T17:00:00.000Z"},{"time":"2025-06-02T18:00:00.000Z"},{"time":"2025-06-02T19:00:00.000Z"}]}}' timeslot = TimeSlot(pl).get_times print(timeslot) def greet(name): return "Hello " + name + "!!" demo = gr.Interface(fn=greet, inputs="text", outputs="text") demo.launch()