Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new google sheets api connection #1084

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dags/vz_google_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
items={"type": "number"},
)
},
tags=["Vision Zero"]
tags=["Vision Zero", "google_sheets"]
)
def get_vz_data():
"""The main function of the SSZ DAG."""
Expand Down Expand Up @@ -147,7 +147,7 @@ def filter_spreadsheets(ds = None, **context):
return sheets

#to get credentials to access google sheets
google_cred = GoogleBaseHook('vz_api_google').get_credentials()
google_cred = GoogleBaseHook('google_sheets_api').get_credentials()

pull_data.partial(
engine=PostgresHook("vz_api_bot").get_sqlalchemy_engine(),
Expand Down
4 changes: 2 additions & 2 deletions dags/wys_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
max_active_runs=5,
template_searchpath=os.path.join(repo_path,'dags/sql'),
schedule='0 17 * * *', # Run at 5:00 PM local time every day
tags=["wys", "data_pull", "partition_create", "data_checks"],
tags=["wys", "data_pull", "partition_create", "data_checks", "google_sheets"],
doc_md=DOC_MD
)
def pull_wys_dag():
Expand Down Expand Up @@ -164,7 +164,7 @@ def read_google_sheets(**context):
wys_postgres = PostgresHook("wys_bot")

#to get credentials to access google sheets
wys_api_hook = GoogleBaseHook('vz_api_google')
wys_api_hook = GoogleBaseHook('google_sheets_api')
cred = wys_api_hook.get_credentials()
service = build('sheets', 'v4', credentials=cred, cache_discovery=False)

Expand Down
4 changes: 2 additions & 2 deletions gis/school_safety_zones/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The DAG consists of two main tasks as shown in the below figure:

## 3. Sheets Credentials

A credential file (named `key.json` in the script) is required to connect to the Google Sheets to pull data, the contents of this file can be downloaded from [the google console](https://console.cloud.google.com/iam-admin/serviceaccounts/details/) if you're logged in to the right google account. This is currently stored in an encrypted Airflow connection: `vz_api_google`.
A credential file (named `key.json` in the script) is required to connect to the Google Sheets to pull data, the contents of this file can be downloaded from [the google console](https://console.cloud.google.com/iam-admin/serviceaccounts/details/) if you're logged in to the right google account. This is currently stored in an encrypted Airflow connection: `google_sheets_api`.

## 4. Adding a new year

Expand All @@ -66,7 +66,7 @@ CREATE TABLE vz_safety_programs_staging.school_safety_zone_yyyy_raw (

### 4.2 Request sharing permission to the new sheet

The sheet must be shared with `vz-sheets@quickstart-1568664221624.iam.gserviceaccount.com`. This ought to be View-only. This email is saved in the Airflow credentials as `wys_cred.service_account_email`.
The sheet must be shared with `sheets-puller@bubbly-fuze-182523.iam.gserviceaccount.com`. This ought to be View-only. This email is associated with the `[email protected]` email and saved in the `google_sheets_api` Airflow connection.

### 4.3 Add the New Google Sheet to Airflow

Expand Down
2 changes: 1 addition & 1 deletion gis/school_safety_zones/schools.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def pull_from_sheet_cli(
connect_url = URL.create("postgresql+psycopg2", **config['DBSETTINGS'])
engine = create_engine(connect_url)

google_cred = GoogleBaseHook('vz_api_google').get_credentials()
google_cred = GoogleBaseHook('google_sheets_api').get_credentials()

if table is None:
table = f"school_safety_zone_{year}_raw"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'AIRFLOW_CONN_HERE_BOT': SAMPLE_CONN.get_uri(),
'AIRFLOW_CONN_RESCU_BOT': SAMPLE_CONN.get_uri(),
'AIRFLOW_CONN_VZ_API_BOT': SAMPLE_CONN.get_uri(),
'AIRFLOW_CONN_VZ_API_GOOGLE': SAMPLE_CONN.get_uri(),
'AIRFLOW_CONN_GOOGLE_SHEETS_API': SAMPLE_CONN.get_uri(),
}


Expand Down