vector-space commited on
Commit
8c1334e
·
verified ·
1 Parent(s): 98f7f25

Create app.py

Browse files

Initial commit

Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #import gradio as gr
2
+ import json
3
+ from datetime import datetime
4
+ import pytz
5
+
6
+ class TimeSlot:
7
+ def __init__(self, payload):
8
+ self.payload = payload
9
+
10
+ def __repr__(self):
11
+ return f"TimeSlot({self.start_time}, {self.end_time})"
12
+
13
+ def get_times(self):
14
+ python_dict = json.loads(self.payload)
15
+ # Extract the keys (dates) from the dictionary
16
+ result = ""
17
+ for date, slots in python_dict['slots'].items():
18
+ # print(f"Available time slots on {date}:")
19
+ result += f"Available time slots on {date}: "
20
+ # Extract the time slots for each date
21
+ for slot in slots:
22
+ # Convert the time string to a datetime object
23
+ time_str = slot['time']
24
+ # Convert the time string to a datetime object
25
+ dt = datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc)
26
+ localDatetime = dt.astimezone(pytz.timezone('America/Sao_Paulo'))
27
+ timeslot = localDatetime.strftime("%H:%M")
28
+ # print(f"{timeslot}", end=", ")
29
+ result = f"{result}{timeslot}, "
30
+ # print() # Print a newline after each date's slots
31
+ result += "\n"
32
+ return result
33
+ 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"}]}}'
34
+ timeslot = TimeSlot(pl).get_times
35
+ print(timeslot)
36
+
37
+
38
+ def greet(name):
39
+ return "Hello " + name + "!!"
40
+
41
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
42
+ demo.launch()