This is a Python project that integrates ChatGPT Actions, Flask API, and Google Sheets for optimizing data capture.
Clone the repository to your local machine.
Install the required packages using pip: pip install -r requirements.txt
- Python 3.9
- Docker
- Azure infrastructure: Azure Container Registry and Azure Web App (Free Tier will do)
- Google Account and new project in Google Developer Console.
The API key for authentication is loaded from an environment variable.
The get_google_sheet
function is responsible for authenticating with Google Sheets using service account credentials and opening a specific spreadsheet.
The application requires two keys:
MY_API_KEY
: this is generated by theutils/generate_api_key.py
script. Keep it safe! The key is used intwo ways:- use the key to create an Azure Web App environment variable.
- encode the key using the
utils/generate_api_key.py
script. Use the encoded API Key in your API Key configuration of the ChatGPT Custom Action.
@app.route('/')
: The index route returns a welcome message. Useful for checking that the Azure web app is up and running.
@app.route('/get_data', methods=['GET'])
: The get_data route is protected by the require_api_key
decorator. It fetches data from a Google Sheet. If there's an error, it returns a JSON response with an error message.
utils/generate_api_key.py
: A utility for generating API keys.
utils/base64_encode.py
: A utility for encoding API keys in base64.
You can build and deploy the application with the following commands:
az login
az acr login --name expensetrackerai
docker build -t expensetrackerai.azurecr.io/google-sheet-reader:latest .
docker tag expensetrackerai.azurecr.io/google-sheet-reader:latest expensetrackerai.azurecr.io/google-sheet-reader:latest
docker push expensetrackerai.azurecr.io/google-sheet-reader:latest
You can test the Flask app using this curl command:
API_KEY="your_api_key"
ENCODED_CREDENTIALS=$(echo -n "$API_KEY:" | base64)
curl -H "Authorization: Basic $ENCODED_CREDENTIALS" https://cybcai.azurewebsites.net/get_data
This project is licensed under the MIT License - see the LICENSE.md file for details.
{
"openapi": "3.1.0",
"info": {
"title": "Tide Tracker API",
"version": "1.0.0",
"description": "API for tracking tide data"
},
"servers": [
{
"url": "url": "https://your-web-app-name.azurewebsites.net"
}
],
"paths": {
"/get_data": {
"get": {
"operationId": "get_data",
"summary": "Receive and process tide data",
"description": "Receives tide data",
"parameters": [],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"date": {
"type": "string",
"description": "The date of the tide information"
},
"tide_type": {
"type": "string",
"description": "Type of tide (High/Low)"
},
"time": {
"type": "string",
"description": "Time of the tide"
},
"height": {
"type": "string",
"description": "Height of the tide"
}
},
"required": [
"date",
"tide_type",
"time",
"height"
]
}
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
}
}
}
}
},
"components": {
"securitySchemes": {
"BasicAuth": {
"type": "http",
"scheme": "basic"
}
},
"schemas": {
"DummyObject": {
"type": "object",
"properties": {
"dummy": {
"type": "string",
"description": "This is a dummy object to prevent schema errors"
}
}
}
}
},
"security": [
{
"BasicAuth": []
}
]
}
openapi: 3.1.0
info:
title: TV Guide API
description: API to retrieve TV program schedules.
version: 1.0.0
servers:
- url: https://cybcai.azurewebsites.net
description: Main (production) server
paths:
/get_data_artetv:
get:
operationId: getProgramsArte
summary: Retrieves the list of TV programs.
description: >
This endpoint returns a list of TV programs including their start times, titles, durations, and options to view
more details.
responses:
"200":
description: A JSON array of TV programs
content:
application/json:
schema:
type: array
items:
type: object
properties:
startTime:
type: string
format: time
description: The start time of the program.
example: 20:51
title:
type: string
description: The title of the program.
example: Regarder A Musée Vous, A Musée Moi Danseuses à la barre, Edgar Degas - Billy Elliot ou presque...
duration:
type: string
description: The duration of the program.
example: 3 min
detailsUrl:
type: string
format: uri
description: URL to view more details about the program.
example: Voir le programme
/get_data_raiuno:
get:
operationId: getProgramsRai
summary: Retrieves the list of TV programs for Arte TV.
description: |
This endpoint returns a list of TV programs for Arte TV including their start times and titles.
responses:
"200":
description: A JSON array of Arte TV programs
content:
application/json:
schema:
type: array
items:
type: object
properties:
startTime:
type: string
format: time
description: The start time of the program.
example: 06:00
title:
type: string
description: The title of the program.
example: RaiNews24 - Previsioni sulla viabilità CCISS Viaggiare informati