36 lines
762 B
Python
36 lines
762 B
Python
from datetime import datetime
|
|
from fastapi import APIRouter
|
|
from app.utils import declension
|
|
from fastapi_utils.tasks import repeat_every
|
|
|
|
from app.config import config
|
|
from app.data_getter import DataGetter
|
|
|
|
router = APIRouter(
|
|
prefix='/api/v1'
|
|
)
|
|
data = DataGetter()
|
|
|
|
|
|
@router.on_event("startup")
|
|
@repeat_every(seconds=7200)
|
|
def start():
|
|
data.fetch()
|
|
|
|
|
|
@router.get("/repos")
|
|
def get_repos():
|
|
return data.repos
|
|
|
|
|
|
@router.get("/code_stats")
|
|
def get_code_stats():
|
|
return data.code_stats
|
|
|
|
|
|
@router.get("/age")
|
|
def get_age():
|
|
today = datetime.today()
|
|
age = today.year - config.birthdate.year - (
|
|
(today.month, today.day) < (config.birthdate.month, config.birthdate.day))
|
|
return declension(age, 'год', 'года', 'лет')
|