-
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
Showing
9 changed files
with
123 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Tauffer Consulting | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 +1,2 @@ | ||
# google-apis-pieces | ||
# [Pieces repository name] | ||
[Description of this Pieces repository] |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[repository] | ||
# The name of the github organization / person owner, e.g. tauffer-consulting. | ||
# Must be in lower-case letters | ||
REGISTRY_NAME = "tauffer-consulting" | ||
|
||
# The name of this Pieces repository | ||
REPOSITORY_NAME = "google-apis-pieces" | ||
REPOSITORY_LABEL = "Google APIs Pieces" | ||
|
||
# The version of this Pieces release | ||
# Attention: changing this will create a new release | ||
VERSION = "0.1.0" |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pandas==2.2.2 | ||
gspread==6.1.2 |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "GetGoogleSheetPiece", | ||
"description": "Read a google sheet file.", | ||
"dependency": { | ||
"requirements": "requirements_0.txt" | ||
}, | ||
"container_resources": { | ||
"requests": { | ||
"cpu": 100, | ||
"memory": 128 | ||
}, | ||
"limits": { | ||
"cpu": 500, | ||
"memory": 512 | ||
} | ||
}, | ||
"tags": [ | ||
"Example" | ||
], | ||
"style": { | ||
"node_label": "Example Sine Piece", | ||
"icon_class_name": "fa-solid:database", | ||
"node_label": "Get Google Sheet" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class InputModel(BaseModel): | ||
spreadsheet_name: str = Field( | ||
title="Spreadsheet Name", | ||
description="Name of the Google Sheets document" | ||
) | ||
worksheet_number: int = Field( | ||
title="Worksheet Number", | ||
description="Number of the worksheet in the Google Sheets document." | ||
) | ||
|
||
|
||
class OutputModel(BaseModel): | ||
output_data: dict = Field( | ||
description="Sleep piece executed" | ||
) | ||
|
||
class SecretsModel(BaseModel): | ||
service_account_data: str = Field( | ||
title="Service Account", | ||
description="Service account JSON data for Google Sheets API", | ||
) |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from domino.base_piece import BasePiece | ||
from .models import InputModel, OutputModel, SecretsModel | ||
import pandas as pd | ||
import gspread | ||
import json | ||
from tempfile import NamedTemporaryFile | ||
|
||
|
||
class GetGoogleSheetPiece(BasePiece): | ||
|
||
def piece_function(self, input_data: InputModel, secrets_data: SecretsModel): | ||
|
||
service_account = secrets_data.service_account_data | ||
if isinstance(service_account, str): | ||
service_account = json.loads(secrets_data.service_account_data) | ||
|
||
with NamedTemporaryFile('w') as tmp: | ||
json.dump(service_account, tmp) | ||
tmp.seek(0) | ||
gc = gspread.service_account(filename=tmp.name) | ||
|
||
# Open the Google Sheet by its title or URL | ||
spreadsheet = gc.open(input_data.spreadsheet_name) | ||
worksheet = spreadsheet.get_worksheet(input_data.worksheet_number) | ||
records = worksheet.get_all_records() | ||
df = pd.DataFrame.from_records(records) | ||
|
||
return OutputModel(output_data=df.to_json()) | ||
|
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from domino.testing import piece_dry_run | ||
import os | ||
|
||
|
||
def test_get_google_sheet_piece(): | ||
assert True |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest==7.4.3 | ||
pytest-cov==4.1.0 |