Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get the historical data from the client.phone.call_logs() method. #342

Open
TzaNalyst opened this issue May 8, 2023 · 1 comment

Comments

@TzaNalyst
Copy link

No description provided.

@TzaNalyst
Copy link
Author

Is there any way that I can get the historical data from the method mentioned above and not the data from the last 24 hours somehow?
Maybe I am missing something but as I read the reference from the zoom API it states that I can get data prior to 6 months.
Any help is appreciated.

Below I will attach a part of my code to actually get the data.

import numpy as np
import pandas as pd
import requests
import json
import pygsheets
from datetime import datetime, timedelta
from zoomus import ZoomClient

def dataframe_to_google_sheet(path_of_auth, sheet_name, worksheet_name, df):
client = pygsheets.authorize(service_account_file = path_of_auth)
sh = client.open(sheet_name)

#get the sheet with the corresponding worksheet name

wks = sh.worksheet('title', worksheet_name)
wks.clear("A1", 'F', '*')
df_rows = df.shape[0]
batch_size = 2000
start_row = 1
while start_row <= df_rows:
    end_row = min(start_row + batch_size -1, df_rows)
    wks.set_dataframe(df.iloc[start_row - 1:end_row, :], start=(start_row, 1), copy_index=False)
    start_row = end_row + 1

def main():

client_path = r"C:\Users\konstantinos.tzaferi\Desktop\Google Service Account Key\my-project-template-378813-ca90ba8ef94a.json"
client = pygsheets.authorize(service_account_file=client_path)

api_key = 'api_key'
api_secret = 'api_secret'
client = ZoomClient(api_key, api_secret)

# Calculate the start date for the call logs
start_date = datetime(2022, 11, 1)
end_date = datetime.now()

call_logs_dict = {
    'call_id': [],
    'user_id' : [],
    'call_type' : [],
    'caller_name': [],
    'employee_email': [],
    'callee_number': [],
    'callee_number_source': [],
    'callee_location': [],
    'call_direction': [],
    'call_duration': [],
    'call_result': [],
    'call_start_time': [],
    'call_end_time': [],
    'call_path': [],
    'company_department': [],
    'office_location': []
}

next_page_token = None
while True:
    call_logs = client.phone.call_logs(start_date=start_date, end_date=end_date, next_page_token=next_page_token).json()
    call_data_list = call_logs.get('call_logs')
    for element in call_data_list:
        call_logs_dict['call_id'].append(element.get('id', np.nan))
        call_logs_dict['user_id'].append(element.get('user_id', np.nan))
        employee_email = client.user.get(id=element.get('user_id', np.nan)).json().get('email', np.nan)
        call_logs_dict['employee_email'].append(employee_email)
        call_logs_dict['call_type'].append(element.get('call_type', np.nan))
        call_logs_dict['caller_name'].append(element.get('caller_name', np.nan))
        call_logs_dict['callee_number'].append(element.get('callee_number', np.nan))
        call_logs_dict['callee_number_source'].append(element.get('callee_number_source', np.nan))
        call_logs_dict['callee_location'].append(element.get('callee_location', np.nan))
        call_logs_dict['call_direction'].append(element.get('direction', np.nan))
        call_logs_dict['call_duration'].append(element.get('duration', np.nan))
        call_logs_dict['call_result'].append(element.get('result', np.nan))
        call_logs_dict['call_start_time'].append(element.get('date_time', np.nan))
        call_logs_dict['call_end_time'].append(element.get('call_end_time', np.nan))
        call_logs_dict['call_path'].append(element.get('path', np.nan))
        call_logs_dict['company_department'].append(element.get('department', np.nan))
        call_logs_dict['office_location'].append(element.get('site',np.nan).get('name', np.nan))
    next_page_token = call_logs.get('next_page_token')
    if not next_page_token:
        break

df_call_logs = pd.DataFrame(call_logs_dict)

dataframe_to_google_sheet(client_path, 'fast_query', 'Database', df_call_logs)

if name == 'main':
main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant