election_text_analysis.download_data

Tools to download all necessary data from ANES.

This includes downloading/unzipping an overall timeseries file, as well as open-ended files by year.

Module Contents

Functions

download_all([filenames_and_urls, output_dir])

Downloads all necessary data to an output data directory. This uses urllib.request

download(filename, url[, output_dir])

Downloads a single URL to a given filename. If the filename ends in

election_text_analysis.download_data.download_all(filenames_and_urls=[('timeseries.zip', 'https://electionstudies.org/anes_timeseries_cdf_csv_20220916/'), ('2020.xlsx', 'https://electionstudies.org/anes_timeseries_2020_redactedopenends_excel_20211118/'), ('2016.xlsx', 'https://electionstudies.org/wp-content/uploads/2016/02/anes_timeseries_2016_redacted_openends.xlsx'), ('2016_full.zip', 'https://electionstudies.org/anes_timeseries_2016/'), ('2012.xlsx', 'https://electionstudies.org/anes_timeseries_2012_openends/'), ('2008.xls', 'https://electionstudies.org/wp-content/uploads/2008/03/anes_timeseries_2008_openends_redacted_Dec2012Revision.xls')], output_dir='downloaded_data')[source]

Downloads all necessary data to an output data directory. This uses urllib.request to download a list of specified links to their specified filenames. This function downloads the overall timeseries file, as well as 1984-2020 open-ended files.

Parameters:
  • output_dir (str (optional, default="downloaded_data")) – An optional output directory to write the downloaded files to (defaults to downloaded_data)

  • filenames_and_urls (list (optional)) – A list of (filename, url) tuples to download

Return type:

None

Examples

>>> # This will download all files to the default downloaded_data directory
>>> download_all()
>>> # This will download all files to a download directory instead
>>> download_all(output_dir="download")
election_text_analysis.download_data.download(filename, url, output_dir='downloaded_data')[source]

Downloads a single URL to a given filename. If the filename ends in *.zip, it is unzipped with the contents placed in the same output_dir.

Parameters:
  • filename (str) – The name of the file to write to. If the filename ends in *.zip, it will be unzipped with the contents placed in the same output_dir

  • url (str) – The URL to download the file from

  • output_dir (str (optional, default="downloaded_data")) – An optional output directory to write the downloaded files to (defaults to downloaded_data)

Return type:

None

Examples

>>> # This will download and unzip the timeseries data
>>> download("timeseries.zip", "https://electionstudies.org/anes_timeseries_cdf_csv_20220916/")
>>> # This will download the 2020 open-ended data
>>> download("2020.xlsx", "https://electionstudies.org/anes_timeseries_2020_redactedopenends_excel_20211118/")