0

I'm currently working on getting the licensing for all our clients and have successfully managed to output to print in the console.

I cannot for the life of me figure out how to output to a csv with the structure like

  • Organization
  • Status
  • Expiration Date

Any help would be appreciated.

for z in get_orgs_json:
org_id = z['id']
get_license_url = base_url + 'organizations/{}/licenseState'.format(org_id) 
get_license_response = requests.get(get_license_url, headers=headers)
get_license_json = get_license_response.json()
print('Organization ' + (z['name']) + ' Current Status ' + (get_license_json['status']) + ' Expiration Date ' + (get_license_json['expirationDate']))
  • Can you show some examples of intermediate info, like typical values for `get_license_response` and `get_license_json`? This would help see where it's failing. I would have expected something like `get_license_json = json.loads(get_license_response)` – beroe Jan 16 '20 at 06:18

2 Answers2

0

Ultimately i used this link to resolve it. Thank you beroe for the response. I ended up writing to an array first and then writing it to a csv.

Using the CSV Module in Python

0

You can use Pandas lib to write to csv file. Like

import pandas as pd

names = ['Job', 'Peter'] # z['id']
status = ['a', 'b'] # get_license_json['status']
expiredDates = ['2013-11-12', '2019-12-31'] # get_license_json['expirationDate']

series = {
    'Organization': names,
    'Status': status,
    'Expired Date': expiredDates,
}

df = pd.DataFrame(series)
df.to_csv('./test.csv')
print(df)
turong
  • 1,474
  • 9
  • 14