Skip to content

A Ruby script to automate the process of retrieving emails from the ACCESS NYC Stat Collector database.

Notifications You must be signed in to change notification settings

NYCOpportunity/accessnyc-email-export

Repository files navigation

ACCESS NYC Email Export

A Ruby script to automate the process of retrieving emails from the ACCESS NYC Stat Collector database. It will export a CSV with emails from a remote database. The CSV will save to a local directory of your choosing.

Requirements

This application uses Ruby version v2.5.8. For more information on installing Ruby refer to the following documentation. Ruby versions can be managed using Ruby Version Manager.

Make sure to have MySQL installed and OpenSSL (which can be done using Homebrew for MacOS).

brew install mysql && brew install openssl

Installation

cd ACCESS-NYC-emails-script
bundle install

If you get the following mysql2 error message:

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

Install the gem with the following command:

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

Then, run bundle install again.

Usage

Fill in the following constants in a .env file in the root of the script. The value for each constant is a string:

Constant Description
DB_HOSTNAME The host of the database to export from.
DB_NAME The name of the database to export from.
DB_USERNAME Username for the database.
DB_PW Password for the database.
LOCAL_PATH The local path to save the exported CSV to.
LOG_LEVEL This may be set to DEBUG for troubleshooting.

The script accepts three arguments for the year, month, and day representing the date to start the range of exported emails. The range will end at the time the script runs.

ruby lambda_function.rb {{ MM }} {{ DD }} {{ YYYY }}

Replace {{ MM }}, {{ DD }}, {{ YYYY }} with the month, day, and year respectively.

ruby lambda_function.rb 06 01 2020

A CSV titled access-nyc-emails-{{ script run date }}.csv will be saved to the directory specified in the LOCAL_PATH constant with email entries starting on 06/01/2020 and ending on the date the script ran.

About

A Ruby script to automate the process of retrieving emails from the ACCESS NYC Stat Collector database.

Resources

Stars

Watchers

Forks

Languages