-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (50 loc) · 2.23 KB
/
Copy pathmain.py
File metadata and controls
58 lines (50 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Cofy API - application entrypoint.
This file bootstraps the CofyApi app and registers the modules you need.
See https://github.com/EnergieID/cofy-api for all available modules & options.
Quick start:
1. Copy .env.example → .env and fill in your values
2. `uv sync` to install dependencies
3. `poe dev` to start the dev server (auto-reloads, reads .env)
"""
import json
from os import environ
from cofy import CofyAPI
from cofy.api import token_verifier
from cofy.modules.directive import DirectiveModule, DynamicBoundaryDirectiveSource
from fastapi import Depends
from directive.dbsource import BoundaryDBSource, SignalDBSource
# ---------------------------------------------------------------------------
# App
# ---------------------------------------------------------------------------
# token_verifier protects all module endpoints with a simple bearer token.
# Map each token to a dict with at least a "name" key.
cofy = CofyAPI(dependencies=[Depends(token_verifier({environ.get("ENERGY_ID_COFY_API_TOKEN"): {"name": "EnergyID"}}))])
# ---------------------------------------------------------------------------
# Modules – uncomment / add the ones you need
# ---------------------------------------------------------------------------
# Each module exposes its own set of API routes under the name you choose.
# Browse the available modules: https://github.com/EnergieID/cofy-api
forecasts = json.loads(environ.get("FORECASTS", "{}"))
for name, id in forecasts.items():
cofy.register_module(
DirectiveModule(
source=DynamicBoundaryDirectiveSource(
signal_source=SignalDBSource(
db_url=environ.get("DB_URL", "postgresql+asyncpg://cofy:cofy@localhost:5432/epv"),
itemid=id,
),
boundary_source=BoundaryDBSource(
db_url=environ.get(
"BOUNDARY_DB_URL", environ.get("DB_URL", "postgresql+asyncpg://cofy:cofy@localhost:5432/epv")
),
cohort_id=name,
),
),
name=name,
description=f"Directive for community {name}",
default_args={
"resolution": "PT15M",
},
)
)