Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
vinicvaz committed Jun 21, 2024
1 parent 0aa5d1e commit c216e14
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 1 deletion.
21 changes: 21 additions & 0 deletions LICENSE
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.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# google-apis-pieces
# [Pieces repository name]
[Description of this Pieces repository]
12 changes: 12 additions & 0 deletions config.toml
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"
2 changes: 2 additions & 0 deletions dependencies/requirements_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas==2.2.2
gspread==6.1.2
25 changes: 25 additions & 0 deletions pieces/GetGoogleSheetPiece/metadata.json
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"
}
}
24 changes: 24 additions & 0 deletions pieces/GetGoogleSheetPiece/models.py
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",
)
29 changes: 29 additions & 0 deletions pieces/GetGoogleSheetPiece/piece.py
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())

6 changes: 6 additions & 0 deletions pieces/GetGoogleSheetPiece/test_get_google_sheet_piece.py
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
2 changes: 2 additions & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest==7.4.3
pytest-cov==4.1.0

0 comments on commit c216e14

Please sign in to comment.