Several enhancements

This commit is contained in:
2025-06-01 20:03:39 +02:00
parent dee65e7aeb
commit 9004c27575
7 changed files with 224 additions and 25 deletions
View File
+55
View File
@@ -0,0 +1,55 @@
import requests
import csv
# === Configuration ===
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN_HERE"
START_DATETIME = "2025-05-19T00:00:00Z"
END_DATETIME = "2025-05-26T23:59:59Z"
OUTPUT_FILE = "calendar.csv"
# === Setup headers ===
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Prefer": 'outlook.timezone="UTC"'
}
# === Initial API endpoint ===
base_url = "https://graph.microsoft.com/v1.0/me/calendarview"
params = {
"$select": "subject,start,end",
"startDateTime": START_DATETIME,
"endDateTime": END_DATETIME
}
# === Event storage ===
all_events = []
# === Fetch all pages ===
print("Fetching events...")
url = base_url
while url:
response = requests.get(url, headers=headers, params=params if url == base_url else None)
if response.status_code != 200:
print("Failed to fetch events:", response.status_code, response.text)
break
data = response.json()
events = data.get("value", [])
all_events.extend(events)
# Get next page link
url = data.get("@odata.nextLink")
# === Write to CSV ===
print(f"Writing {len(all_events)} events to {OUTPUT_FILE}...")
with open(OUTPUT_FILE, "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=["subject", "start", "end"])
writer.writeheader()
for e in all_events:
writer.writerow({
"subject": e.get("subject", ""),
"start": e.get("start", {}).get("dateTime", ""),
"end": e.get("end", {}).get("dateTime", "")
})
print("Done.")
+21
View File
@@ -0,0 +1,21 @@
from msal import PublicClientApplication
CLIENT_ID = "2a1cb9f1-2c0c-46ad-9887-fd2bb835bc2e"
AUTHORITY = "https://login.microsoftonline.com/consumers" # or your tenant ID
SCOPES = ["https://graph.microsoft.com/Calendars.Read"]
USERNAME = "zisco@zisco.at"
PASSWORD = "3S1punk08_114$" # ⚠️ Storing passwords is risky
app = PublicClientApplication(CLIENT_ID, authority=AUTHORITY)
result = app.acquire_token_by_username_password(
username=USERNAME,
password=PASSWORD,
scopes=SCOPES
)
if "access_token" in result:
print("Access token:", result["access_token"])
else:
print("Error:", result.get("error_description"))