Files
zisco_zerf/app/CalenderExport.py

65 lines
2.0 KiB
Python

import requests
import pandas as pd
from msal import ConfidentialClientApplication
# Replace with your values
CLIENT_ID = "2a1cb9f1-2c0c-46ad-9887-fd2bb835bc2e"
CLIENT_SECRET = "8fH8Q~RAzS0Q8dG.PEBtb~twd6Nh5Bwp2_o1idzx"
AUTHORITY = "https://login.microsoftonline.com/40f52dd9-93f5-4e52-b871-652ef67bb0d0"
SCOPES = ["https://graph.microsoft.com/.default"]
app = ConfidentialClientApplication(
CLIENT_ID,
authority=AUTHORITY,
client_credential=CLIENT_SECRET
)
result = app.acquire_token_for_client(scopes=SCOPES)
access_token = result.get("access_token")
if access_token:
# Example: Get user ID for a given email
headers = {"Authorization": f"Bearer {access_token}"}
url = "https://graph.microsoft.com/v1.0/users"
response = requests.get(url, headers=headers).json()
print(response)
email = "zisco@zisco.at"
url = f"https://graph.microsoft.com/v1.0/users/{email}"
response = requests.get(url, headers=headers).json()
user_id = response.get("id")
print("User ID:", user_id)
user_id = "f92b34ea-a2ea-4a09-b9a8-012988cd4417"
user_id = "35bf5591-13f2-4c1a-9d1b-8818eb0eaa43"
# Get events
#headers = {"Authorization": f"Bearer {access_token}"}
url = f"https://graph.microsoft.com/v1.0/users/{user_id}/calendar/events?$top=10000"
events = []
while url:
res = requests.get(url, headers=headers).json()
events.extend(res.get("value", []))
url = res.get("@odata.nextLink") # pagination
# Parse to DataFrame
df = pd.DataFrame([{
"Subject": e.get("subject"),
"Start": e["start"]["dateTime"],
"End": e["end"]["dateTime"],
"Location": e.get("location", {}).get("displayName"),
"Body": e.get("bodyPreview")
} for e in events])
# Save to CSV
df.to_csv("outlook_calendar_export.csv", index=False)
print("Exported to outlook_calendar_export.csv")
else:
print("Auth failed:", result.get("error_description"))
#bafad0ef-0e6e-4388-b335-e6a8a373bebd