Last active
August 3, 2017 09:55
-
-
Save jluczak/bf035fe549270478706aed22b43cef85 to your computer and use it in GitHub Desktop.
Find header images for external events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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