Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,208 @@ CLIENT_SECRET_KEY = os.getenv('CLIENT_SECRET_KEY')
|
|
11 |
AUTHORITY_URL = 'https://login.microsoftonline.com/common'
|
12 |
REDIRECT_URI = 'https://huggingface.co/spaces/awacke1/MSGraphAPI'
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
ProductNaming='''
|
15 |
ππ Git Cosmos Glow: Graph & Mobile Flow π±π«
|
16 |
ππ Cosmic Git Wit: Graph Power, Mobile Hit π²β¨
|
@@ -531,10 +733,13 @@ def handle_onedrive_integration(access_token):
|
|
531 |
|
532 |
|
533 |
|
534 |
-
|
535 |
def main():
|
536 |
st.title("π¦ MS Graph API with AI & Cloud Integration for M365")
|
537 |
|
|
|
|
|
|
|
|
|
538 |
st.sidebar.title("π M365 Products")
|
539 |
st.sidebar.write("Select products to integrate:")
|
540 |
|
@@ -546,6 +751,7 @@ def main():
|
|
546 |
st.sidebar.write(f"AI Capabilities: {details['ai_capabilities']}")
|
547 |
st.sidebar.write(f"Graph Solution: {details['graph_solution']}")
|
548 |
|
|
|
549 |
request_scopes = BASE_SCOPES.copy()
|
550 |
for product in selected_products:
|
551 |
request_scopes.extend(PRODUCT_SCOPES[product]['scopes'])
|
@@ -581,19 +787,25 @@ def main():
|
|
581 |
if user_info:
|
582 |
st.sidebar.write(f"π Hello, {user_info.get('displayName', 'User')}!")
|
583 |
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
|
598 |
if __name__ == "__main__":
|
599 |
main()
|
|
|
11 |
AUTHORITY_URL = 'https://login.microsoftonline.com/common'
|
12 |
REDIRECT_URI = 'https://huggingface.co/spaces/awacke1/MSGraphAPI'
|
13 |
|
14 |
+
def sticky_menu():
|
15 |
+
st.markdown(
|
16 |
+
"""
|
17 |
+
<style>
|
18 |
+
.menu-bar {
|
19 |
+
position: -webkit-sticky;
|
20 |
+
position: sticky;
|
21 |
+
top: 0;
|
22 |
+
background-color: white;
|
23 |
+
z-index: 999;
|
24 |
+
padding: 10px;
|
25 |
+
border-bottom: 1px solid #f0f0f0;
|
26 |
+
}
|
27 |
+
.menu-bar a {
|
28 |
+
margin: 0 10px;
|
29 |
+
padding: 5px;
|
30 |
+
text-decoration: none;
|
31 |
+
color: #000;
|
32 |
+
}
|
33 |
+
.menu-bar a:hover {
|
34 |
+
background-color: #f0f0f0;
|
35 |
+
}
|
36 |
+
</style>
|
37 |
+
<div class="menu-bar">
|
38 |
+
<a href="#dashboard">1οΈβ£ Dashboard</a>
|
39 |
+
<a href="#landing-page">π Landing Page</a>
|
40 |
+
<a href="#upcoming-events">π
Upcoming Events</a>
|
41 |
+
<a href="#schedule">π Schedule</a>
|
42 |
+
<a href="#agenda">π Agenda</a>
|
43 |
+
<a href="#event-details">π Event Details</a>
|
44 |
+
<a href="#add-event">β Add Event</a>
|
45 |
+
<a href="#filter-by">π Filter By</a>
|
46 |
+
</div>
|
47 |
+
""",
|
48 |
+
unsafe_allow_html=True
|
49 |
+
)
|
50 |
+
|
51 |
+
def dashboard(access_token):
|
52 |
+
st.subheader("1οΈβ£ Dashboard")
|
53 |
+
|
54 |
+
# Timeframe selector
|
55 |
+
timeframe = st.selectbox("Select Timeframe", ["Day", "Week", "Month"])
|
56 |
+
|
57 |
+
now = datetime.now()
|
58 |
+
|
59 |
+
if timeframe == "Day":
|
60 |
+
start_time = now.replace(hour=0, minute=0, second=0)
|
61 |
+
end_time = now.replace(hour=23, minute=59, second=59)
|
62 |
+
elif timeframe == "Week":
|
63 |
+
start_time = now - timedelta(days=now.weekday()) # Start of the week (Monday)
|
64 |
+
end_time = start_time + timedelta(days=6)
|
65 |
+
elif timeframe == "Month":
|
66 |
+
start_time = now.replace(day=1, hour=0, minute=0, second=0)
|
67 |
+
next_month = (now.month % 12) + 1
|
68 |
+
end_time = start_time.replace(month=next_month, day=1) - timedelta(days=1)
|
69 |
+
|
70 |
+
# Fetch and display calendar events for the selected timeframe
|
71 |
+
events = make_api_call(access_token, f"me/calendarView?startDateTime={start_time.isoformat()}&endDateTime={end_time.isoformat()}&$orderby=start/dateTime")
|
72 |
+
|
73 |
+
if events and 'value' in events:
|
74 |
+
st.write(f"π
Events from {start_time.date()} to {end_time.date()}")
|
75 |
+
for event in events['value']:
|
76 |
+
start_date = datetime.fromisoformat(event['start']['dateTime'][:-1])
|
77 |
+
st.write(f"**{event['subject']}** | {start_date.strftime('%Y-%m-%d %H:%M')}")
|
78 |
+
st.write("---")
|
79 |
+
else:
|
80 |
+
st.write("No events found or unable to fetch events.")
|
81 |
+
|
82 |
+
def landing_page():
|
83 |
+
st.subheader("π Landing Page")
|
84 |
+
st.write("Welcome to the app! Use the menu above to navigate.")
|
85 |
+
|
86 |
+
def upcoming_events(access_token):
|
87 |
+
st.subheader("π
Upcoming Events")
|
88 |
+
|
89 |
+
# Show upcoming events from the current date
|
90 |
+
now = datetime.now()
|
91 |
+
events = make_api_call(access_token, f"me/calendar/events?$top=10&$orderby=start/dateTime&$filter=start/dateTime ge {now.isoformat()}")
|
92 |
+
|
93 |
+
if events and 'value' in events:
|
94 |
+
st.write("Upcoming Events:")
|
95 |
+
for event in events['value']:
|
96 |
+
start_date = datetime.fromisoformat(event['start']['dateTime'][:-1])
|
97 |
+
st.write(f"**{event['subject']}** | {start_date.strftime('%Y-%m-%d %H:%M')}")
|
98 |
+
st.write("---")
|
99 |
+
else:
|
100 |
+
st.write("No upcoming events.")
|
101 |
+
|
102 |
+
def schedule(access_token):
|
103 |
+
st.subheader("π Schedule")
|
104 |
+
|
105 |
+
# Display a weekly or daily schedule from the current date
|
106 |
+
now = datetime.now()
|
107 |
+
week_start = now - timedelta(days=now.weekday()) # Start of the week (Monday)
|
108 |
+
week_end = week_start + timedelta(days=6)
|
109 |
+
|
110 |
+
st.write(f"Schedule for the week {week_start.strftime('%Y-%m-%d')} to {week_end.strftime('%Y-%m-%d')}")
|
111 |
+
|
112 |
+
events = make_api_call(access_token, f"me/calendarView?startDateTime={week_start.isoformat()}&endDateTime={week_end.isoformat()}&$orderby=start/dateTime")
|
113 |
+
|
114 |
+
if events and 'value' in events:
|
115 |
+
for event in events['value']:
|
116 |
+
start_date = datetime.fromisoformat(event['start']['dateTime'][:-1])
|
117 |
+
st.write(f"**{event['subject']}** | {start_date.strftime('%Y-%m-%d %H:%M')}")
|
118 |
+
st.write("---")
|
119 |
+
else:
|
120 |
+
st.write("No events found.")
|
121 |
+
|
122 |
+
def agenda(access_token):
|
123 |
+
st.subheader("π Agenda")
|
124 |
+
|
125 |
+
# Display a list of tasks or meetings
|
126 |
+
tasks = make_api_call(access_token, 'me/todo/lists')
|
127 |
+
if tasks and 'value' in tasks:
|
128 |
+
st.write("Agenda Items:")
|
129 |
+
for task in tasks['value']:
|
130 |
+
st.write(f"Task: {task['title']}")
|
131 |
+
st.write("---")
|
132 |
+
else:
|
133 |
+
st.write("No tasks or agenda items.")
|
134 |
+
|
135 |
+
def event_details(access_token):
|
136 |
+
st.subheader("π Event Details")
|
137 |
+
|
138 |
+
# Fetch and display details for a specific event
|
139 |
+
event_id = st.text_input("Enter Event ID")
|
140 |
+
|
141 |
+
if event_id:
|
142 |
+
event = make_api_call(access_token, f'me/events/{event_id}')
|
143 |
+
if event:
|
144 |
+
st.write(f"Event: {event['subject']}")
|
145 |
+
st.write(f"Start: {event['start']['dateTime']}")
|
146 |
+
st.write(f"End: {event['end']['dateTime']}")
|
147 |
+
st.write(f"Description: {event.get('bodyPreview', 'No description')}")
|
148 |
+
else:
|
149 |
+
st.write("Unable to fetch event details.")
|
150 |
+
|
151 |
+
def add_event(access_token):
|
152 |
+
st.subheader("β Add Event")
|
153 |
+
|
154 |
+
# Create event
|
155 |
+
event_subject = st.text_input("Event Subject")
|
156 |
+
event_date = st.date_input("Event Date")
|
157 |
+
event_time = st.time_input("Event Time")
|
158 |
+
|
159 |
+
if st.button("Add Event"):
|
160 |
+
event_start = datetime.combine(event_date, event_time)
|
161 |
+
event_end = event_start + timedelta(hours=1)
|
162 |
+
|
163 |
+
new_event = {
|
164 |
+
"subject": event_subject,
|
165 |
+
"start": {
|
166 |
+
"dateTime": event_start.isoformat(),
|
167 |
+
"timeZone": "UTC"
|
168 |
+
},
|
169 |
+
"end": {
|
170 |
+
"dateTime": event_end.isoformat(),
|
171 |
+
"timeZone": "UTC"
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
result = make_api_call(access_token, 'me/events', method='POST', data=new_event)
|
176 |
+
if result:
|
177 |
+
st.success("Event added successfully!")
|
178 |
+
else:
|
179 |
+
st.error("Failed to add event.")
|
180 |
+
|
181 |
+
def filter_by(access_token):
|
182 |
+
st.subheader("π Filter By")
|
183 |
+
|
184 |
+
# Filter calendar events by title, date range, or organizer
|
185 |
+
filter_by_title = st.text_input("Event Title Contains")
|
186 |
+
filter_by_start_date = st.date_input("Start Date After", datetime.now() - timedelta(days=30))
|
187 |
+
filter_by_end_date = st.date_input("End Date Before", datetime.now() + timedelta(days=30))
|
188 |
+
|
189 |
+
filters = []
|
190 |
+
if filter_by_title:
|
191 |
+
filters.append(f"contains(subject, '{filter_by_title}')")
|
192 |
+
if filter_by_start_date:
|
193 |
+
filters.append(f"start/dateTime ge {filter_by_start_date.isoformat()}T00:00:00Z")
|
194 |
+
if filter_by_end_date:
|
195 |
+
filters.append(f"end/dateTime le {filter_by_end_date.isoformat()}T23:59:59Z")
|
196 |
+
|
197 |
+
filter_query = " and ".join(filters) if filters else ''
|
198 |
+
events_endpoint = f"me/calendarView?startDateTime={filter_by_start_date.isoformat()}&endDateTime={filter_by_end_date.isoformat()}&$orderby=start/dateTime"
|
199 |
+
|
200 |
+
if filter_query:
|
201 |
+
events_endpoint += f"&$filter={filter_query}"
|
202 |
+
|
203 |
+
events = make_api_call(access_token, events_endpoint)
|
204 |
+
|
205 |
+
if events and 'value' in events:
|
206 |
+
for event in events['value']:
|
207 |
+
start_date = datetime.fromisoformat(event['start']['dateTime'][:-1])
|
208 |
+
st.write(f"**{event['subject']}** | {start_date.strftime('%Y-%m-%d %H:%M')}")
|
209 |
+
st.write("---")
|
210 |
+
else:
|
211 |
+
st.write("No events found.")
|
212 |
+
|
213 |
+
|
214 |
+
|
215 |
+
|
216 |
ProductNaming='''
|
217 |
ππ Git Cosmos Glow: Graph & Mobile Flow π±π«
|
218 |
ππ Cosmic Git Wit: Graph Power, Mobile Hit π²β¨
|
|
|
733 |
|
734 |
|
735 |
|
|
|
736 |
def main():
|
737 |
st.title("π¦ MS Graph API with AI & Cloud Integration for M365")
|
738 |
|
739 |
+
# Sticky Menu
|
740 |
+
sticky_menu()
|
741 |
+
|
742 |
+
# Sidebar Menu for Product Selection
|
743 |
st.sidebar.title("π M365 Products")
|
744 |
st.sidebar.write("Select products to integrate:")
|
745 |
|
|
|
751 |
st.sidebar.write(f"AI Capabilities: {details['ai_capabilities']}")
|
752 |
st.sidebar.write(f"Graph Solution: {details['graph_solution']}")
|
753 |
|
754 |
+
# Handle menu navigation
|
755 |
request_scopes = BASE_SCOPES.copy()
|
756 |
for product in selected_products:
|
757 |
request_scopes.extend(PRODUCT_SCOPES[product]['scopes'])
|
|
|
787 |
if user_info:
|
788 |
st.sidebar.write(f"π Hello, {user_info.get('displayName', 'User')}!")
|
789 |
|
790 |
+
# Handle navigation based on the selected section from the sticky menu
|
791 |
+
selected_section = st.experimental_get_query_params().get('section', ['dashboard'])[0]
|
792 |
+
|
793 |
+
if selected_section == 'dashboard':
|
794 |
+
dashboard(access_token)
|
795 |
+
elif selected_section == 'landing-page':
|
796 |
+
landing_page()
|
797 |
+
elif selected_section == 'upcoming-events':
|
798 |
+
upcoming_events(access_token)
|
799 |
+
elif selected_section == 'schedule':
|
800 |
+
schedule(access_token)
|
801 |
+
elif selected_section == 'agenda':
|
802 |
+
agenda(access_token)
|
803 |
+
elif selected_section == 'event-details':
|
804 |
+
event_details(access_token)
|
805 |
+
elif selected_section == 'add-event':
|
806 |
+
add_event(access_token)
|
807 |
+
elif selected_section == 'filter-by':
|
808 |
+
filter_by(access_token)
|
809 |
|
810 |
if __name__ == "__main__":
|
811 |
main()
|