Skip to content

Instantly share code, notes, and snippets.

View brienna's full-sized avatar
🤸

Brienna Herold brienna

🤸
View GitHub Profile
@brienna
brienna / get_NYT_archive_data.py
Last active January 13, 2023 15:44
Requests article data from The New York Times Archive API over a period time
def send_request(date):
'''Sends a request to the NYT Archive API for given date.'''
base_url = 'https://api.nytimes.com/svc/archive/v1/'
url = base_url + '/' + date[0] + '/' + date[1] + '.json?api-key=' + YOUR_API_KEY
response = requests.get(url).json()
time.sleep(6)
return response
def is_valid(article, date):
@brienna
brienna / generate_topical_headlines.py
Last active May 25, 2020 20:24
Generates headlines about a specific topic such as the coronavirus
total = 25
topic = ['coronavirus', 'covid19', 'covid-19', 'sars-cov-2', 'sarscov2', 'sars-cov2', 'virus', 'pandemic']
generated_headlines = []
while len(generated_headlines) < total:
headline = model.make_sentence()
if headline is not None:
on_topic = bool([word for word in headline.split(' ') if word.lower() in topic])
if on_topic:
generated_headlines.append(headline)