Hello im trying to get the data from API and save to excel using python but after executing script execl file is created but no data is showing in file
import requests
import base64
import openpyxl
def pull_email_list():
base_url = 'https://ID_Calamari.calamari.io/api/'
username = 'calamari'
password = 'API_KEY
# Choose data from
date_from_global = '2024-01-01'
date_to_global = '2024-12-31'
# Get a list of employees from API
req = 'employees/v1/list'
response = get_post_response(req, {"page": 0}, username, password, base_url)
list_length = response['totalPages']
employee_info = []
for i in range(list_length):
response = get_post_response(req, {"page": i}, username, password, base_url)
employees = response['employees']
for employee in employees:
holidays = pull_public_holidays_for_employee_dates(employee['email'], date_from_global, date_to_global, username, password, base_url)
for holiday in holidays:
employee_info.append([employee['email'], holiday['name'], holiday['start'], holiday['end']])
return employee_info
def pull_public_holidays_for_employee_dates(employee_email, date_from, date_to, username, password, base_url):
req = 'holiday/v1/find'
data = {
'employee': employee_email,
'from': date_from,
'to': date_to
}
response = get_post_response(req, data, username, password, base_url)
return response
def get_post_response(req, data, username, password, base_url):
auth_header = 'Basic ' + base64.b64encode((username + ':' + password).encode()).decode()
headers = {'Authorization': auth_header, 'Content-Type': 'application/json'}
response = requests.post(base_url + req, headers=headers, json=data)
return response.json()
def write_to_excel(data, filename):
wb = openpyxl.Workbook()
ws = wb.active
ws.append(['Employee Email', 'Holiday Name', 'Start Date', 'End Date'])
for item in data:
ws.append(item)
wb.save(filename)
def main():
employee_info = pull_email_list()
write_to_excel(employee_info, 'calamari_leave_data.xlsx')
print("Data has been successfully saved to calamari_leave_data.xlsx")
if __name__ == "__main__":
main()
Any help??