Code Monkey home page Code Monkey logo

gpt-tide-info's Introduction

Title

This is a Python project that integrates ChatGPT Actions, Flask API, and Google Sheets for optimizing data capture.

Installing

Clone the repository to your local machine. Install the required packages using pip: pip install -r requirements.txt

Prerequisites

  • 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.

Application Overview

API Key Configuration

The API key for authentication is loaded from an environment variable.

Google Sheets Configuration

The get_google_sheet function is responsible for authenticating with Google Sheets using service account credentials and opening a specific spreadsheet.

API Key Requirement

The application requires two keys:

  • MY_API_KEY: this is generated by the utils/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.

Routes

@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.

Utilities

utils/generate_api_key.py: A utility for generating API keys. utils/base64_encode.py: A utility for encoding API keys in base64.

Running with Docker

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

Testing

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

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Addendum: ChatGPT Actions JSON Schema

Schema for Tide Info

{
  "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": []
    }
  ]
}

Schema for ArteTV and RaiUno

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

gpt-tide-info's People

Contributors

raoulbia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.