Skip to content

Instantly share code, notes, and snippets.

View brienna's full-sized avatar
🤸

Brienna Herold brienna

🤸
View GitHub Profile
@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)
@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 / parse_article_details.py
Last active May 2, 2020 00:57
Collects details for each article in The New York Times over a period of time
data = {'headline': [],
'date': [],
'doc_type': [],
'material_type': [],
'section': [],
'keywords': []}
for response in responses: # For each response, get all the articles
articles = response['response']['docs']
for article in articles: # For each article, make sure it falls within our date range
latitude longitude
44.52634219999999 -109.05653079999999
44.2633149 -104.9502538
41.311366899999996 -105.5911007
42.8500769 -106.32517490000001
41.311366899999996 -105.5911007
41.1399814 -104.8202462
42.833014 -108.73067250000001
44.7538408 -108.7573525
43.381669099999996 -87.9406453
@brienna
brienna / us-states.js
Last active March 10, 2020 20:01
GeoJSON preview
{
"type": "Feature",
"properties": {
"name": "Alabama",
"density": 94.65
},
"geometry": ...
...
}
# Set the backend to use mplcairo
import matplotlib, mplcairo
print('Default backend: ' + matplotlib.get_backend())
matplotlib.use("module://mplcairo.macosx")
print('Backend is now ' + matplotlib.get_backend())
# IMPORTANT: Import these libraries only AFTER setting the backend
import matplotlib.pyplot as plt, numpy as np
from matplotlib.font_manager import FontProperties
@brienna
brienna / emojis_plotted.py
Last active April 12, 2024 11:20
Plotting emojis with Matplotlib
import matplotlib.pyplot as plt, numpy as np
from matplotlib.font_manager import FontProperties
# Load Apple Color Emoji font
prop = FontProperties(fname='/System/Library/Fonts/Apple Color Emoji.ttc')
# Set up plot
freqs = [301, 96, 53, 81, 42]
labels = ['😊', '😱', '😂', '😄', '😛']
plt.figure(figsize=(12,8))
@brienna
brienna / 10.08.2018.5.py
Created October 9, 2018 02:00
Full code
import boto3, configparser, os, botocore, json
from bs4 import BeautifulSoup
from datetime import datetime
s3resource = None
def setup():
"""Creates S3 resource & sets configs to enable download."""
print('Connecting to Amazon S3...')
@brienna
brienna / 10.08.2018.4.py
Created October 9, 2018 01:59
Download astro-ph source files
import json
from datetime import datetime
def begin_download():
"""Sets up download of tars from arxiv bucket."""
print('Beginning tar download & extraction...')
# Create a reusable Paginator
paginator = s3resource.meta.client.get_paginator('list_objects_v2')
@brienna
brienna / 10.08.2018.3.py
Created October 9, 2018 01:58
Explore the manifest file
from bs4 import BeautifulSoup
def explore_metadata():
"""Explores arxiv bucket metadata."""
print('\narxiv bucket metadata:')
with open('src/arXiv_src_manifest.xml', 'r') as manifest:
soup = BeautifulSoup(manifest, 'xml')