Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -188,10 +188,48 @@ def make_api_call(access_token, endpoint, method='GET', data=None):
|
|
188 |
st.error(f"API call failed: {response.status_code} - {response.text}")
|
189 |
return None
|
190 |
|
|
|
191 |
def handle_outlook_integration(access_token):
|
192 |
st.subheader("π§ Outlook Integration")
|
193 |
st.markdown(f"[Open Outlook]({PRODUCT_SCOPES['π§ Outlook']['link']})")
|
194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
# Read emails
|
196 |
emails = make_api_call(access_token, 'me/messages?$top=10&$orderby=receivedDateTime desc')
|
197 |
if emails and 'value' in emails:
|
@@ -253,11 +291,49 @@ def handle_outlook_integration(access_token):
|
|
253 |
else:
|
254 |
st.error("Failed to delete email.")
|
255 |
|
256 |
-
|
257 |
def handle_calendar_integration(access_token):
|
258 |
st.subheader("π
Calendar Integration")
|
259 |
st.markdown(f"[Open Calendar]({PRODUCT_SCOPES['π
Calendar']['link']})")
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
# Get the current month's start and end dates
|
262 |
now = datetime.now()
|
263 |
start_of_month = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
|
|
188 |
st.error(f"API call failed: {response.status_code} - {response.text}")
|
189 |
return None
|
190 |
|
191 |
+
|
192 |
def handle_outlook_integration(access_token):
|
193 |
st.subheader("π§ Outlook Integration")
|
194 |
st.markdown(f"[Open Outlook]({PRODUCT_SCOPES['π§ Outlook']['link']})")
|
195 |
|
196 |
+
# Filters for emails
|
197 |
+
st.write("### Filter Emails:")
|
198 |
+
filter_by_sender = st.text_input("Sender Email")
|
199 |
+
filter_by_subject = st.text_input("Subject Contains")
|
200 |
+
filter_by_date = st.date_input("Emails received after", datetime.now() - timedelta(days=30))
|
201 |
+
|
202 |
+
# Create query filters
|
203 |
+
filters = []
|
204 |
+
if filter_by_sender:
|
205 |
+
filters.append(f"from/emailAddress/address eq '{filter_by_sender}'")
|
206 |
+
if filter_by_subject:
|
207 |
+
filters.append(f"contains(subject, '{filter_by_subject}')")
|
208 |
+
if filter_by_date:
|
209 |
+
filters.append(f"receivedDateTime ge {filter_by_date.isoformat()}T00:00:00Z")
|
210 |
+
|
211 |
+
filter_query = " and ".join(filters) if filters else ''
|
212 |
+
|
213 |
+
# Fetch emails with applied filters
|
214 |
+
emails_endpoint = 'me/messages?$top=10'
|
215 |
+
if filter_query:
|
216 |
+
emails_endpoint += f"&$filter={filter_query}&$orderby=receivedDateTime desc"
|
217 |
+
|
218 |
+
emails = make_api_call(access_token, emails_endpoint)
|
219 |
+
if emails and 'value' in emails:
|
220 |
+
for email in emails['value']:
|
221 |
+
with st.expander(f"From: {email['from']['emailAddress']['name']} - Subject: {email['subject']}"):
|
222 |
+
st.write(f"Received: {email['receivedDateTime']}")
|
223 |
+
st.write(f"Body: {email['bodyPreview']}")
|
224 |
+
else:
|
225 |
+
st.write("No emails found or unable to fetch emails.")
|
226 |
+
|
227 |
+
|
228 |
+
|
229 |
+
def handle_outlook_integration_old(access_token):
|
230 |
+
st.subheader("π§ Outlook Integration")
|
231 |
+
st.markdown(f"[Open Outlook]({PRODUCT_SCOPES['π§ Outlook']['link']})")
|
232 |
+
|
233 |
# Read emails
|
234 |
emails = make_api_call(access_token, 'me/messages?$top=10&$orderby=receivedDateTime desc')
|
235 |
if emails and 'value' in emails:
|
|
|
291 |
else:
|
292 |
st.error("Failed to delete email.")
|
293 |
|
|
|
294 |
def handle_calendar_integration(access_token):
|
295 |
st.subheader("π
Calendar Integration")
|
296 |
st.markdown(f"[Open Calendar]({PRODUCT_SCOPES['π
Calendar']['link']})")
|
297 |
|
298 |
+
# Filters for calendar events
|
299 |
+
st.write("### Filter Calendar Events:")
|
300 |
+
filter_by_title = st.text_input("Event Title Contains")
|
301 |
+
filter_by_start_date = st.date_input("Start Date After", datetime.now() - timedelta(days=30))
|
302 |
+
filter_by_end_date = st.date_input("End Date Before", datetime.now() + timedelta(days=30))
|
303 |
+
|
304 |
+
# Create query filters
|
305 |
+
filters = []
|
306 |
+
if filter_by_title:
|
307 |
+
filters.append(f"contains(subject, '{filter_by_title}')")
|
308 |
+
if filter_by_start_date:
|
309 |
+
filters.append(f"start/dateTime ge {filter_by_start_date.isoformat()}T00:00:00Z")
|
310 |
+
if filter_by_end_date:
|
311 |
+
filters.append(f"end/dateTime le {filter_by_end_date.isoformat()}T23:59:59Z")
|
312 |
+
|
313 |
+
filter_query = " and ".join(filters) if filters else ''
|
314 |
+
|
315 |
+
# Fetch events with applied filters
|
316 |
+
events_endpoint = f"me/calendarView?startDateTime={filter_by_start_date.isoformat()}T00:00:00&endDateTime={filter_by_end_date.isoformat()}T23:59:59"
|
317 |
+
if filter_query:
|
318 |
+
events_endpoint += f"&$filter={filter_query}&$orderby=start/dateTime"
|
319 |
+
|
320 |
+
events = make_api_call(access_token, events_endpoint)
|
321 |
+
|
322 |
+
if events and 'value' in events:
|
323 |
+
st.write("### Upcoming Events")
|
324 |
+
for event in events['value']:
|
325 |
+
start_date = datetime.fromisoformat(event['start']['dateTime'][:-1]) # Remove 'Z' from the end
|
326 |
+
st.write(f"**{event['subject']}** | {start_date.strftime('%Y-%m-%d %H:%M')}")
|
327 |
+
st.write("---")
|
328 |
+
else:
|
329 |
+
st.write("No events found or unable to fetch events.")
|
330 |
+
|
331 |
+
|
332 |
+
|
333 |
+
def handle_calendar_integration_old(access_token):
|
334 |
+
st.subheader("π
Calendar Integration")
|
335 |
+
st.markdown(f"[Open Calendar]({PRODUCT_SCOPES['π
Calendar']['link']})")
|
336 |
+
|
337 |
# Get the current month's start and end dates
|
338 |
now = datetime.now()
|
339 |
start_of_month = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|