Ah yes, I was a bit quick in the script. 😛
If you wan't to write the data to a simple text file, it would be something like
#!/usr/bin/env python3
import meraki
def do_stuff(p_id,p_name):
with open("filename.txt","a") as fp:
line = f"id: {p_id} \t name: {p_name}"
fp.writelines(line)
def main():
API_KEY = 'aaa'
dashboard = meraki.DashboardAPI(API_KEY)
organization_id = 'bbb'
sites = dashboard.organizations.getOrganizationNetworks(
organization_id, total_pages='all'
)
for site in sites:
if "DK" in site['name']:
do_stuff(site['id'],site['name'])
if __name__ == "__main__":
main()
If we're talking about CSV data try something like, where you'd like all sites where the name contains "DK", we can do something like;
#!/usr/bin/env python3
import meraki
import csv
def main():
API_KEY = 'aaa'
dashboard = meraki.DashboardAPI(API_KEY)
organization_id = 'bbb'
sites = dashboard.organizations.getOrganizationNetworks(
organization_id, total_pages='all'
)
ListOfDkSites = []
for site in sites:
if "DK" in site['name']:
ListOfDkSites.append([site['id'],site['name']])
header = ["id","name"]
with open("filename.csv","w") as fp:
writer = csv.writer(fp)
writer.writerow(header)
writer.writerows(ListOfDkSites)
if __name__ == "__main__":
main()
Depending on how much data there is, you'd might want to break the CSV writer up in multiple writes, and append the file, rather than writing it all in one go.
I haven't run the code myself, but it's the gist of it.
LinkedIn :::
https://blog.rhbirkelund.dk/Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution
🙂All code examples are provided as is. Responsibility for Code execution lies solely your own.