Skip to content

Instantly share code, notes, and snippets.

View chrimaho's full-sized avatar

Chris Mahoney chrimaho

View GitHub Profile
# Successful Response: status_code=200 ----
class Success(BaseModel):
Success:str="Response Text"
# Validation Error: status_code=422 ----
class ValidationError(BaseModel):
Message:str="Details about the validation error"
# Server Error: status_code=500 ----
class InternalServerError(BaseModel):
# Remove all files within a diretory ----
def remove_dir(dir:str) -> None:
if exists(dir):
rmtree(dir, ignore_errors=True)
return None
# Instantiate App ----
app = FastAPI \
( title=TITLE
, description=DESCRIPTION
, version=VERSION
, openapi_tags=\
[ {"name":"App Info", "description":"Information about the App"}
, {"name":"Main Process", "description":"The main Endpoints for th App"}
]
, contact=CONTACT_DETAILS
# Set Landing Page ----
with open("./templates/landing_page.html") as file:
LANDING_PAGE = file.read() \
.format \
( TITLE = TITLE
, DESCRIPTION = DESCRIPTION
, VERSION = VERSION
, GIT_URL = GIT_URL
, API_ENDPOINT = API_ENDPOINT
, REPO_DIR = REPO_DIR
# Compile Variables ----
TITLE = config(option='TITLE', default='Update from Git', cast=str)
DESCRIPTION = config \
( option='DESCRIPTION'
, default='Automated update process for pulling from Git repo upon webhook call.'
, cast=str
)
VERSION = config(option='VERSION', default='0.0.1', cast=str)
GIT_URL = config(option='GIT_URL', cast=str)
API_ENDPOINT = config(option="API_ENDPOINT", cast=str, default="/api/webhook")
# Import Libraries ----
from sys import exc_info
from decouple import config
from fastapi import FastAPI, Query
from pydantic import BaseModel
from fastapi.responses import PlainTextResponse, JSONResponse, HTMLResponse
from git import Repo
from os.path import exists
from shutil import rmtree
version: "3.8"
name: update-from-git
services:
listener:
build:
context: ../
dockerfile: docker/uvicorn.Dockerfile
container_name: listener
environment:
- GIT_URL=https://github.com/chrimaho/code-snippets.git
# Base image
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
# Load requirements
COPY requirements.txt .
# Install dependencies
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --upgrade uvicorn[standard]
fastapi
gitpython
python-decouple
{
"Function": {
"scope": "python",
"prefix": ["fun","def"],
"description": "Insert new function.",
"body":
[ "def ${1:function_name}(${2:param_1_name}:${3:param_1_type}=${4:param_1_default}, ${5:param_2_name}:${6:param_2_type}=${7:param_2_default}):"
, " '''"
, " # ${1:function_name}()"
, " "