コード例 #1
0
from requests.exceptions import BaseHTTPError
from fastapi import APIRouter, Form

from app.core import config
from app.custom_router import AutopilotRoute
from app.models import (
    UserDocument,
    screening_not_in_danger,
    screening_pre_results_warning,
)
from app.services import capture_message, NovelCOVIDApi
from app.services.endless_medical_api import EndlessMedicalAPI
from app.utils import features_mapping, reponse_mappings, outcomes_mapping

self_screening = APIRouter()
self_screening.route_class = AutopilotRoute
endless_medical_api = EndlessMedicalAPI(config)
novelcovid_api = NovelCOVIDApi(config)


@self_screening.post("/self-screening/start")
def self_screening_start(UserIdentifier: str = Form(...),
                         Memory: str = Form(...)):
    """
    Starts the screening process
    :param: UserIdentifier: Phone number from Twilio
    :param: Memory: JSON Stringified object from Twilio
    """
    memory = json.loads(Memory)
    twilio = memory.pop("twilio")
コード例 #2
0
            and request.headers.get("content-type") != "application/json"
            # we could check for a specific endpoint:
            # request.url.path == "/json"
            # could also check for the type of error:
            # exc.errors()[0]["type"] == "value_error.jsondecode"
        ):
        # we should redirect to the form endpoint
        return RedirectResponse(url="/form")
    else:
        # otherwise we just have a bad request and we do the normal thing
        return await request_validation_exception_handler(request, exc)


# isolating on a separater router to make testing a little more obvious
form_to_json_router = APIRouter(prefix="/form_to_json")
form_to_json_router.route_class = FormToJSONRoute


@form_to_json_router.post("/form")
def form_to_json_form_endpoint(user: UserData = Depends(UserFormData)):
    return user


@form_to_json_router.post("/json")
def form_to_json_json_endpoint(user: UserData):
    return user


@form_to_json_router.get("/query")
def form_to_json_query_endpoint(user: UserData = Depends(UserQueryData)):
    return user
コード例 #3
0
from starlette.requests import Request

from woolgatherer.db.session import get_db
from woolgatherer.db.utils import load_query
from woolgatherer.db_models.figmentator import FigmentatorStatus
from woolgatherer.metrics import get_diff_score, remove_stopwords, rouge
from woolgatherer.models.range import split_sentences
from woolgatherer.utils.auth import parse_scopes
from woolgatherer.utils.routing import CompressibleRoute
from woolgatherer.utils.templating import TemplateResponse
from woolgatherer.utils import ngram_overlaps

MAX_PUBLIC_EDITS = 10

router = APIRouter()
router.route_class = CompressibleRoute


async def get_finalized_suggestions(
    db: Database,
    status: Sequence[FigmentatorStatus] = (FigmentatorStatus.active, )
) -> AsyncGenerator[Mapping, None]:
    """ Load the finalized suggestions """
    async with aiofiles.open(os.path.join("static", "game_blacklist.txt"),
                             "rt") as blacklist_file:
        blacklist = [l.strip() for l in await blacklist_file.readlines()]

    async for row in db.iterate(
            await load_query("finalized_suggestions.sql"),
        {
            "status": status,
コード例 #4
0
import json

from fastapi import APIRouter, HTTPException, Form
from loguru import logger

from app.custom_router import AutopilotRoute
from app.models import UserDocument
from app.utils import phone_to_country

user_greeting = APIRouter()
user_greeting.route_class = AutopilotRoute


@logger.catch
@user_greeting.post("/greeting")
def greet_user(UserIdentifier: str = Form(...)):
    """
    User greet endpoint
    :param: UserIdentifier: user's phone number from Twilio
    """

    # Check the country from the phone number
    try:
        country = phone_to_country(UserIdentifier)
    except ValueError:
        raise HTTPException(status_code=400, detail="Invalid phone number")

    user = UserDocument.get_by_phone(UserIdentifier)

    # Greeting the user since already exists
    if user is not None:
コード例 #5
0
from fastapi import Depends, FastAPI, Header, HTTPException

from fastapi import APIRouter

from app.core.casbin_auth import CasbinRoute

router = APIRouter()
router.route_class = CasbinRoute


fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]


@router.get("/items/", summary= "create items", description="it is 1")
async def read_item(skip: int = 0, limit: int = 10):
    return fake_items_db[skip : skip + limit]

@router.get("/items2/", summary= "create items2", description="it is 2")
async def read_item(skip: int = 0, limit: int = 10):
    return fake_items_db[skip : skip + limit]
コード例 #6
0
ファイル: utils.py プロジェクト: socek/jet_py
def make_router(**kwargs: Any) -> APIRouter:
    router = APIRouter(**kwargs)
    router.default_response_class = ZLibORJSONResponse
    router.route_class = ZLibRoute
    return router