Download Publisher Logos

From WPRDC Wiki
Revision as of 17:26, 9 December 2022 by Steve (talk | contribs) (added brief description and the code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This script will download a copy of each publisher's logo on the Regional Data Center.

#!/usr/bin/python3
# Download logo images into the current directory for all publishers 
#   on the WPRDC data portal.

import requests

ORG_LIST_URL = 'https://data.wprdc.org/api/3/action/organization_list'
ORG_DATA_URL = 'https://data.wprdc.org/api/3/action/organization_show'

orgs = requests.get(ORG_LIST_URL).json()['result']

for org in orgs:
  print(org, end='')
  org_data = requests.get(f'{ORG_DATA_URL}?id={org}').json()['result']
  if "image_display_url" in org_data:
    img_url = org_data['image_display_url']
    r = requests.get(img_url)
    file_ext = org_data['image_url'].split('.')[-1]
    file_name = f"{org}.{file_ext}"
    print('.' + file_ext, ' ✅')
    with open(file_name, 'wb') as f:
      f.write(r.content)