Skip to content

Instantly share code, notes, and snippets.

@kwinkunks
Last active October 26, 2022 09:36
Show Gist options
  • Save kwinkunks/5dafc61b7d67f2133035908af47c0b51 to your computer and use it in GitHub Desktop.
Save kwinkunks/5dafc61b7d67f2133035908af47c0b51 to your computer and use it in GitHub Desktop.
Get earthquakes on your birthday
import pandas as pd
from datetime import timedelta
from urllib.parse import urlencode
def birthquakes(birthday:str) -> pd.DataFrame:
"""
Make a DataFrame of earthquakes on a given day.
Example: birthquake("1971-05-26")
"""
birthday = pd.to_datetime(birthday)
url = 'https://earthquake.usgs.gov/fdsnws/event/1/query'
query = {
'format': 'csv',
'starttime': birthday,
'endtime': birthday + timedelta(days=1),
}
return pd.read_csv(f"{url}?{urlencode(query)}")
birthquakes('26 May 1971')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment