diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 36041b4..697d6cb 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -5,9 +5,12 @@ import requests from datetime import datetime from fastapi import FastAPI -from app.routes import router from starlette.middleware.cors import CORSMiddleware +from app.routes import router +from utils import declension +from app.models import Project + app = FastAPI() app.add_middleware( @@ -19,6 +22,9 @@ app.add_middleware( ) app.include_router(router) +repos = [] +code_stats = {} + @app.on_event("startup") def start(): @@ -55,9 +61,12 @@ def load_code_stats(): code_stats[el['name']] = '' if hours > 0: - code_stats[el['name']] = get_declension(hours, 'час', 'часа', 'часов') + ' ' + code_stats[el['name']] = declension(hours, 'час', 'часа', 'часов') + ' ' if minutes > 0: - code_stats[el['name']] += get_declension(minutes, 'минуту', 'минуты', 'минут') + ' ' + code_stats[el['name']] += declension(minutes, 'минуту', 'минуты', 'минут') + ' ' if code_stats[el['name']] == '': code_stats.pop(el['name']) - time.sleep(7200) \ No newline at end of file + time.sleep(7200) + + +__all__ = ['code_stats', 'repos', 'app'] \ No newline at end of file diff --git a/backend/app/config.py b/backend/app/config.py new file mode 100644 index 0000000..d8e75bc --- /dev/null +++ b/backend/app/config.py @@ -0,0 +1,13 @@ +from datetime import datetime +from pydantic import BaseSettings + + +class Config(BaseSettings): + host: str = '127.0.0.1' + port: int = 8888 + birthdate: datetime + + +config = Config(_env_file='.env') + +__all__ = ['config'] diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.py new file mode 100644 index 0000000..8bd6ce3 --- /dev/null +++ b/backend/app/models/__init__.py @@ -0,0 +1 @@ +from project import Project \ No newline at end of file diff --git a/backend/app/models/project.py b/backend/app/models/project.py new file mode 100644 index 0000000..2243ee0 --- /dev/null +++ b/backend/app/models/project.py @@ -0,0 +1,8 @@ +from dataclasses import dataclass + + +@dataclass +class Project: + name: str + description: str + link: str diff --git a/backend/app/routes.py b/backend/app/routes.py index 742c060..3c83c9a 100644 --- a/backend/app/routes.py +++ b/backend/app/routes.py @@ -1 +1,27 @@ +from datetime import datetime +from fastapi import APIRouter +from app.utils import declension + +from app import code_stats, repos +from app.config import config + router = APIRouter() + + +@router.get("/api/get_repos") +def get_repos(): + return repos + + +@router.get("/api/get_code_stats") +def get_code_stats(): + return code_stats + + +@router.get("/api/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, 'год', 'года', 'лет') + diff --git a/backend/poetry.lock b/backend/poetry.lock index 8a5a401..e65b970 100644 --- a/backend/poetry.lock +++ b/backend/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "anyio" @@ -21,18 +21,6 @@ doc = ["packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx-rtd-theme"] test = ["contextlib2", "coverage[toml] (>=4.5)", "hypothesis (>=4.0)", "mock (>=4)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "uvloop (<0.15)", "uvloop (>=0.15)"] trio = ["trio (>=0.16,<0.22)"] -[[package]] -name = "argparse" -version = "1.4.0" -description = "Python command-line parsing library" -category = "main" -optional = false -python-versions = "*" -files = [ - {file = "argparse-1.4.0-py2.py3-none-any.whl", hash = "sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314"}, - {file = "argparse-1.4.0.tar.gz", hash = "sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4"}, -] - [[package]] name = "certifi" version = "2022.12.7" @@ -359,4 +347,4 @@ standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "7ac5dfa898af0c96eeb29f6592b9fe62c558ae5f367150a876f62da54a531d36" +content-hash = "701467840b1645daf1e62f8aaf1321f73043db620457d49330ae14461a8c7ebe" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 30a7288..5ee220e 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -9,7 +9,6 @@ readme = "README.md" python = "^3.10" uvicorn = "^0.22.0" fastapi = "^0.95.1" -argparse = "^1.4.0" requests = "^2.29.0" diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..7ddd4aa --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,12 @@ +FROM node:20-alpine +WORKDIR /app + +COPY package*.json ./ +RUN yarn install --production=true + +EXPOSE 3000 + +COPY . . +CMD ["yarn", "dev", "--port", "3000"] + +