"""Utilities.""" import asyncio import logging import math import signal import sys import time from dataclasses import fields, is_dataclass from datetime import date, datetime, time as time_, timedelta, timezone from typing import AsyncIterator, Awaitable, Callable, Iterator, Union import eventkit as ev globalErrorEvent = ev.Event() """ Event to emit global exceptions. """ EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc) UNSET_INTEGER = 2**31 - 1 UNSET_DOUBLE = sys.float_info.max def df(objs, labels=None): """ Create pandas DataFrame from the sequence of same-type objects. When a list of labels is given then only retain those labels and drop the rest. """ import pandas as pd
from typing import Optional from fastapi import FastAPI from fastapi import Request import uvicorn as uv import eventkit as ev app = FastAPI() gh_event = ev.Event() @app.get("/") def read_root(): return {"Hello": "World"} # http post http://localhost:5000/webhooks/github hi=there --json @app.post("/webhooks/github") async def github_webhook(req: Request): gh_event.emit(await req.json()) return "OK" def process_github(json): print(json["hi"]) @app.get("/items/{item_id}") def read_item(item_id: int, q: Optional[str] = None): return {"item_id": item_id, "q": q}