This file contains hidden or 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
# 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): |
This file contains hidden or 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
# Remove all files within a diretory ---- | |
def remove_dir(dir:str) -> None: | |
if exists(dir): | |
rmtree(dir, ignore_errors=True) | |
return None |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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") |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
# 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] |
This file contains hidden or 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
fastapi | |
gitpython | |
python-decouple |
This file contains hidden or 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
{ | |
"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}()" | |
, " " |