-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoom_meeting_summary.py
241 lines (216 loc) · 8.89 KB
/
zoom_meeting_summary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
"""Module for processing and summarizing Zoom meeting data."""
import json
import logging
import os
from datetime import datetime, timedelta
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from dateutil import parser
from config import CLIENT_ID, CLIENT_SECRET, ACCOUNT_ID
from tqdm import tqdm
# Set up logging
log_filename = f"zoom_summary_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_filename),
]
)
# Console logger
console = logging.getLogger('console')
console.setLevel(logging.INFO)
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter('%(message)s'))
console.addHandler(console_handler)
# Auth cache file
AUTH_CACHE_FILE = "auth_cache.json"
# Set up requests session with retry logic
session = requests.Session()
retries = Retry(total=5, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
session.mount('https://', HTTPAdapter(max_retries=retries))
def log_response(response):
logging.info(f"Response Status Code: {response.status_code}")
logging.info(f"Response Headers: {json.dumps(dict(response.headers), indent=2)}")
try:
logging.info(f"Response Content: {json.dumps(response.json(), indent=2)}")
except json.JSONDecodeError:
logging.info(f"Response Content (non-JSON): {response.text}")
def load_cached_token():
if os.path.exists(AUTH_CACHE_FILE):
with open(AUTH_CACHE_FILE, 'r') as f:
cache = json.load(f)
expiration = datetime.fromisoformat(cache['expiration'])
if expiration > datetime.now():
logging.info("Using cached access token")
return cache['access_token']
return None
def save_token_to_cache(access_token, expires_in):
expiration = datetime.now() + timedelta(seconds=expires_in)
cache = {
'access_token': access_token,
'expiration': expiration.isoformat()
}
with open(AUTH_CACHE_FILE, 'w') as f:
json.dump(cache, f)
logging.info("Saved access token to cache")
def get_access_token():
cached_token = load_cached_token()
if cached_token:
return cached_token
url = "https://zoom.us/oauth/token"
data = {
"grant_type": "account_credentials",
"account_id": ACCOUNT_ID,
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET
}
try:
response = session.post(url, data=data, timeout=10)
response.raise_for_status()
log_response(response)
token_data = response.json()
access_token = token_data["access_token"]
expires_in = token_data["expires_in"]
save_token_to_cache(access_token, expires_in)
logging.info("Successfully obtained new access token")
return access_token
except requests.exceptions.RequestException as e:
logging.error(f"Error obtaining access token: {e}")
log_response(response)
raise Exception("Failed to obtain access token")
def get_user_id(access_token):
url = "https://api.zoom.us/v2/users/me"
headers = {
"Authorization": f"Bearer {access_token}"
}
try:
response = session.get(url, headers=headers, timeout=10)
response.raise_for_status()
log_response(response)
user_id = response.json()["id"]
logging.info(f"Successfully obtained user ID: {user_id}")
return user_id
except requests.exceptions.RequestException as e:
logging.error(f"Failed to obtain user ID: {e}")
log_response(response)
raise Exception("Failed to obtain user ID")
def get_meeting_details(access_token, meeting_id):
url = f"https://api.zoom.us/v2/meetings/{meeting_id}"
headers = {
"Authorization": f"Bearer {access_token}"
}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
log_response(response)
return response.json()
except requests.exceptions.RequestException as e:
logging.error(f"Failed to fetch meeting details for meeting {meeting_id}: {e}")
log_response(response)
return None
def get_meetings(access_token, user_id, start_date, end_date):
url = f"https://api.zoom.us/v2/users/{user_id}/meetings"
headers = {
"Authorization": f"Bearer {access_token}"
}
params = {
"type": "scheduled",
"page_size": 300,
"from": start_date.isoformat(),
"to": end_date.isoformat()
}
meetings = []
try:
while True:
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
log_response(response)
data = response.json()
meetings.extend(data["meetings"])
if "next_page_token" in data and data["next_page_token"]:
params["next_page_token"] = data["next_page_token"]
else:
break
logging.info(f"Successfully fetched {len(meetings)} meetings")
return meetings
except requests.exceptions.RequestException as e:
logging.error(f"Failed to fetch meetings: {e}")
log_response(response)
raise Exception("Failed to fetch meetings")
def get_meeting_participants(access_token, meeting_id):
url = f"https://api.zoom.us/v2/report/meetings/{meeting_id}/participants"
headers = {
"Authorization": f"Bearer {access_token}"
}
params = {
"page_size": 300
}
participants = []
try:
while True:
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
log_response(response)
data = response.json()
participants.extend(data["participants"])
if "next_page_token" in data and data["next_page_token"]:
params["next_page_token"] = data["next_page_token"]
else:
break
logging.info(f"Successfully fetched {len(participants)} participants for meeting {meeting_id}")
return participants
except requests.exceptions.RequestException as e:
logging.error(f"Failed to fetch participants for meeting {meeting_id}: {e}")
log_response(response)
return []
def calculate_participant_duration(join_time, leave_time):
join = parser.parse(join_time)
leave = parser.parse(leave_time)
duration = leave - join
return int(duration.total_seconds() / 60) # Duration in minutes
def summarize_meetings(access_token, meetings):
summary = []
for meeting in tqdm(meetings, desc="Processing meetings", unit="meeting"):
start_time = parser.parse(meeting["start_time"])
scheduled_duration = meeting["duration"]
end_time = start_time + timedelta(minutes=scheduled_duration)
participants = get_meeting_participants(access_token, meeting["id"])
participant_summaries = []
for participant in participants:
duration = calculate_participant_duration(participant["join_time"], participant["leave_time"])
participant_summaries.append({
"name": participant["name"],
"email": participant.get("email", "N/A"),
"duration": f"{duration} minutes"
})
summary.append({
"topic": meeting["topic"],
"start_time": start_time.strftime("%Y-%m-%d %H:%M"),
"end_time": end_time.strftime("%Y-%m-%d %H:%M"),
"scheduled_duration": f"{scheduled_duration} minutes",
"participants": participant_summaries
})
logging.info(f"Summarized {len(summary)} meetings")
return summary
def main():
try:
console.info("Starting Zoom meeting summary script")
access_token = get_access_token()
console.info("[OK] Authenticated")
user_id = get_user_id(access_token)
console.info("[OK] Fetched user info")
end_date = datetime.now()
start_date = end_date - timedelta(days=14)
console.info(f"Fetching meetings from {start_date.date()} to {end_date.date()}")
meetings = get_meetings(access_token, user_id, start_date, end_date)
console.info(f"[OK] Fetched {len(meetings)} meetings")
summary = summarize_meetings(access_token, meetings)
console.info(f"\nMeeting summary for the last two weeks ({start_date.date()} to {end_date.date()}):")
console.info(json.dumps(summary, indent=2))
console.info("Script completed successfully")
except Exception as e:
console.exception(f"An error occurred: {e}")
if __name__ == "__main__":
main()