Skip to content

Instantly share code, notes, and snippets.

@jluczak
Last active August 3, 2017 09:55
Show Gist options
  • Save jluczak/bf035fe549270478706aed22b43cef85 to your computer and use it in GitHub Desktop.
Save jluczak/bf035fe549270478706aed22b43cef85 to your computer and use it in GitHub Desktop.
Find header images for external events
import csv
import pycurl
from io import BytesIO
import json
import requests
buffer = BytesIO()
with open('events_2016.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in spamreader:
url = 'https://mercury.postlight.com/parser?url=%s' % row[2]
headers = {'x-api-key':'p9jYJHappN5dg7rwGMu49pQKl74kPIca7Kx8GCez'}
r = requests.get(url,headers=headers)
d=r.json()
with open('header_image_2016.csv', 'a', newline='') as csvfile:
spamwriter=csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
if 'lead_image_url' in d:
while d['lead_image_url'] is not None:
spamwriter.writerow([row[0]]+['header_image']+(d['lead_image_url'].split(',')))
break
else:
spamwriter.writerow([row[0]]+['header_image']+'Not found'.split(','))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment