-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bae482
commit 832ff11
Showing
3 changed files
with
66 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import os | ||
import gspread | ||
import typing | ||
|
||
|
||
class SheetsApiClient: | ||
"""interface for all functionality with google sheets | ||
|
@@ -20,16 +20,17 @@ class SheetsApiClient: | |
] | ||
|
||
def __init__(self): | ||
self.connect() | ||
self.client = self.connect() | ||
self.spreadsheet = self.client.open(type(self).SPREADSHEET_NAME) | ||
self.worksheet = self.spreadsheet.get_worksheet(0) | ||
|
||
def connect(self): | ||
@staticmethod | ||
def connect(): | ||
"""connects to Google Sheets API service using private key file | ||
""" | ||
try: | ||
secret_file = os.path.join(os.getcwd(), "google_sheets_credentials.json") | ||
self.client = gspread.service_account(secret_file) | ||
return gspread.service_account(secret_file) | ||
except OSError as e: | ||
print(e) | ||
|
||
|
@@ -48,18 +49,20 @@ def append_rows(self, rows: [[str]]): | |
self._check_row(row) | ||
self.worksheet.append_rows(rows) | ||
|
||
def notify_arthur(self, message: str): | ||
def email(self, message: str, email_addresses: [str]): | ||
"""Shares the spreadsheet with arthur, along with the message in an email | ||
Args: | ||
message (str): | ||
message (str): message to be sent | ||
email_addresses ([str]): recipients of notification | ||
""" | ||
self.spreadsheet.share( | ||
"[email protected]", | ||
perm_type="user", | ||
role="writer", | ||
notify=True, | ||
email_message=message, | ||
) | ||
for email_address in email_addresses: | ||
self.spreadsheet.share( | ||
email_address, | ||
perm_type="user", | ||
role="writer", | ||
notify=True, | ||
email_message=message, | ||
) | ||
|
||
@staticmethod | ||
def _check_row(row: []): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters