Last active
September 16, 2019 16:26
-
-
Save KalebNyquist/cb33f7814b9940c6bdc16079e60c7734 to your computer and use it in GitHub Desktop.
Medium Post
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 requests | |
headers = {"Authorization" : "Bearer [INSERT AIRTABLE API KEY HERE]"} | |
params = ( | |
('maxRecords', '100'), | |
('view', 'Grid view')) | |
URL = 'https://api.airtable.com/v0/appgaUkvDLKnYOmdA/URLS%20to%20Process' | |
response = requests.get(URL, params = params, headers = headers) | |
airtable_dictionary = response.json() | |
urls = [] | |
for entry in range(0, len(airtable_dictionary['records'])): | |
url = airtable_dictionary['records'][entry]['fields']['URL'] | |
urls.append(url) |
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 newspaper | |
article = newspaper.Article(urls[0]) | |
article.download() | |
article.parse() | |
article.nlp() |
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
def publish_date(article): | |
from datetime import datetime | |
dtime = article.publish_date | |
if dtime != None: | |
strftime = dtime.strftime("%Y-%m-%d") | |
date = strftime | |
if dtime == None: | |
strtime = article.meta_data['article']['published'] | |
date = strtime[0:10] | |
return date | |
def determine_media(article): | |
media = article.is_media_news() | |
if media == False: | |
media = "False" | |
else: | |
media = "True" | |
return media | |
def determine_opinion(article): | |
if 'opinion' in article.meta_data['article'].keys(): | |
opinion = article.meta_data['article']['opinion'] | |
else: | |
opinion = "Uncategorized" | |
return opinion |
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
upload_dict = { | |
"fields": { | |
"URL" : article.url, | |
"Title" : article.title, | |
"Date" : publish_date(article), | |
"Author(s)" : article.authors, | |
"Site Name" : article.meta_data['og']['site_name'], | |
"Media" : determine_media(article), | |
"Opinion" : determine_opinion(article), | |
"Keywords" : article.keywords, | |
"Site Twitter" : article.meta_data['twitter']['site'], | |
"Text" : article.text, | |
}, | |
"typecast" : True | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment