awacke1 commited on
Commit
e52db35
·
verified ·
1 Parent(s): dfddcab

Delete bacckup1013.app.py

Browse files
Files changed (1) hide show
  1. bacckup1013.app.py +0 -174
bacckup1013.app.py DELETED
@@ -1,174 +0,0 @@
1
- import msal
2
- import os
3
- import streamlit as st
4
- import webbrowser as wb
5
- import requests
6
-
7
-
8
- from msal import PublicClientApplication
9
-
10
- APPLICATION_ID_KEY = os.getenv('APPLICATION_ID_KEY')
11
- CLIENT_SECRET_KEY = os.getenv('CLIENT_SECRET_KEY')
12
- AUTHORIZATION_KEY = os.getenv('AUTHORIZATION_KEY')
13
-
14
- #st.write(APPLICATION_ID_KEY)
15
- #st.write(CLIENT_SECRET_KEY)
16
-
17
- authority_url = 'https://login.microsoftonline.com/consumers'
18
- base_url = 'https://graph.microsoft.com/v1.0/'
19
- endpoint = base_url + 'me'
20
-
21
- SCOPES = ['User.Read','User.Export.All']
22
-
23
- # Authenticate with Auth Code
24
- client_instance = msal.ConfidentialClientApplication(
25
- client_id=APPLICATION_ID_KEY, client_credential=CLIENT_SECRET_KEY, authority=authority_url
26
- )
27
-
28
- authorization_request_url = client_instance.get_authorization_request_url(SCOPES)
29
- st.write('Connecting to MSGraph with url:' + authorization_request_url)
30
- wb.open(authorization_request_url, new=True)
31
-
32
- access_token = client_instance.acquire_token_by_authorization_code(
33
- code=AUTHORIZATION_KEY,
34
- scopes=SCOPES)
35
-
36
- try:
37
- access_token_id = access_token['access_token']
38
- headers = {'Authorization': 'Bearer ' + access_token_id}
39
-
40
- endpoint = base_url + 'me'
41
- response = requests.get(endpoint, headers=headers)
42
-
43
- st.write(response)
44
- st.write(response.json)
45
- except:
46
- st.write('No auth key returned from MS graph - redirect issue?')
47
-
48
- # URLs used in this sample app to demonstrate MS Graph in Python
49
- # https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/~/Authentication/appId/d36c689d-3c61-4be6-a230-c09fc54cf80d/objectId/ece93996-1d7c-4b39-abc5-de51487073ed/isMSAApp~/false/defaultBlade/Overview/appSignInAudience/AzureADandPersonalMicrosoftAccount/servicePrincipalCreated~/true
50
- # https://developer.microsoft.com/en-us/graph/graph-explorer
51
- # https://chatgpt.com/c/67065b64-e2a8-800d-8b64-69cfe7aaed7f
52
- # https://www.google.com/search?q=msal+pypi&oq=msal+pypi&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIICAEQABgWGB4yCAgCEAAYFhgeMg0IAxAAGIYDGIAEGIoFMg0IBBAAGIYDGIAEGIoFMg0IBRAAGIYDGIAEGIoFMgoIBhAAGIAEGKIEMgoIBxAAGIAEGKIEMgoICBAAGIAEGKIE0gEIMTk2NGowajeoAgCwAgA&sourceid=chrome&ie=UTF-8
53
- # https://www.youtube.com/watch?v=1Jyd7SA-0kI&list=PLHgX2IExbFot3M2dudQEbTVEk9ikRJ2h5&t=972s
54
- # https://huggingface.co/spaces/awacke1/MSGraphAPI
55
-
56
-
57
- # Initialize MSAL client
58
- def get_msal_app():
59
- return ConfidentialClientApplication(
60
- CLIENT_ID,
61
- authority=AUTHORITY_URL,
62
- client_credential=CLIENT_SECRET
63
- )
64
-
65
- # Get access token
66
- def get_access_token():
67
- app = get_msal_app()
68
- result = app.acquire_token_silent(SCOPES, account=None)
69
- if not result:
70
- result = app.acquire_token_for_client(scopes=SCOPES)
71
- if "access_token" in result:
72
- return result['access_token']
73
- else:
74
- st.error("Could not obtain access token.")
75
- st.stop()
76
-
77
- # Placeholder functions for MS Graph API interactions
78
- def get_upcoming_events():
79
- # Implement API call to get upcoming events
80
- return []
81
-
82
- def get_schedule():
83
- # Implement API call to get schedule
84
- return []
85
-
86
- def add_event(event_details):
87
- # Implement API call to add a new event
88
- pass
89
-
90
- def get_event_details(event_id):
91
- # Implement API call to get event details
92
- return {}
93
-
94
- def filter_events(filter_criteria):
95
- # Implement API call to filter events
96
- return []
97
-
98
- # Sidebar navigation
99
- st.sidebar.title("Navigation")
100
- menu = st.sidebar.radio("Go to", [
101
- "1️⃣ Dashboard with Widgets",
102
- "🏠 Landing Page",
103
- "📅 Upcoming Events",
104
- "📆 Schedule",
105
- "📝 Agenda",
106
- "🔍 Event Details",
107
- "➕ Add Event",
108
- "🔎 Filter By"
109
- ])
110
-
111
- # Main content area
112
- st.title("Simple Streamlit App with MS Graph API")
113
-
114
- if menu == "1️⃣ Dashboard with Widgets":
115
- st.header("1️⃣ Dashboard with Widgets")
116
- st.write("Widgets will be displayed here.")
117
- # Add your widgets here
118
-
119
- elif menu == "🏠 Landing Page":
120
- st.header("🏠 Landing Page")
121
- st.write("Welcome to the app!")
122
- # Add landing page content here
123
-
124
- elif menu == "📅 Upcoming Events":
125
- st.header("📅 Upcoming Events")
126
- events = get_upcoming_events()
127
- for event in events:
128
- st.write(event)
129
- # Display upcoming events
130
-
131
- elif menu == "📆 Schedule":
132
- st.header("📆 Schedule")
133
- schedule = get_schedule()
134
- st.write(schedule)
135
- # Display schedule
136
-
137
- elif menu == "📝 Agenda":
138
- st.header("📝 Agenda")
139
- # Display agenda
140
- st.write("Your agenda for today.")
141
-
142
- elif menu == "🔍 Event Details":
143
- st.header("🔍 Event Details")
144
- event_id = st.text_input("Enter Event ID")
145
- if event_id:
146
- event_details = get_event_details(event_id)
147
- st.write(event_details)
148
- # Display event details based on ID
149
-
150
- elif menu == "➕ Add Event":
151
- st.header("➕ Add Event")
152
- event_title = st.text_input("Event Title")
153
- event_date = st.date_input("Event Date")
154
- event_time = st.time_input("Event Time")
155
- if st.button("Add Event"):
156
- event_details = {
157
- "title": event_title,
158
- "date": event_date,
159
- "time": event_time
160
- }
161
- add_event(event_details)
162
- st.success("Event added successfully!")
163
- # Form to add new event
164
-
165
- elif menu == "🔎 Filter By":
166
- st.header("🔎 Filter Events")
167
- filter_criteria = st.text_input("Enter filter criteria")
168
- if filter_criteria:
169
- filtered_events = filter_events(filter_criteria)
170
- st.write(filtered_events)
171
- # Filter events based on criteria
172
-
173
- else:
174
- st.write("Please select a menu option.")