Все? заработаешь?

This commit is contained in:
Andrey 2023-05-03 21:36:53 +03:00
parent 5b51c55046
commit 99e551fcb5
15 changed files with 62 additions and 153 deletions

View file

@ -1,12 +1,12 @@
FROM python:3.10-alpine
RUN mkdir /app COPY /app /app
COPY pyproject.toml /app
WORKDIR /app
RUN pip install poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
WORKDIR .
COPY . .
RUN poetry config virtualenvs.create false \
&& poetry install $(test "$YOUR_ENV" == production && echo "--no-dev") --no-interaction --no-ansi
CMD ["poetry", "run", "python", "app/__main__.py"]

View file

@ -1,11 +1,11 @@
from datetime import datetime
from datetime import date
from pydantic import BaseSettings
class Config(BaseSettings):
host: str = '127.0.0.1'
port: int = 8888
birthdate: datetime = datetime(2007, 10, 13)
birthdate: date = date(2007, 10, 13)
config = Config(_env_file='.env')

View file

@ -6,28 +6,31 @@ from fastapi_utils.tasks import repeat_every
from app.config import config
from app.data_getter import DataGetter
router = APIRouter()
router = APIRouter(
prefix='/api/v1'
)
data = DataGetter()
@router.on_event('startup')
@router.on_event("startup")
@repeat_every(seconds=7200)
def start():
data.fetch()
@router.get("/api/get_repos")
@router.get("/repos")
def get_repos():
return data.repos
@router.get("/api/get_code_stats")
@router.get("/code_stats")
def get_code_stats():
return data.code_stats
@router.get("/api/get_age")
@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, 'год', 'года', 'лет')

View file

@ -12,19 +12,4 @@ def declension(num: int, one: str, two: str, five: str):
return f'{str(num)} {five}'
def load_repos() -> list:
while True:
try:
resp = requests.get("https://git.mootfrost.dev/api/v1/repos/search",
params={'limit': 64,
'sort': 'updated',
'order': 'desc'}).json()
except RequestException as e:
logging.error(f'{datetime.now()}: Error while updating projects: {e}')
return
repos = []
for repo in resp['data']:
repos.append(Project(repo["name"], repo["description"], repo["html_url"]))
return repos
__all__ = ['declension']

108
backend/poetry.lock generated
View file

@ -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,36 +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 = "apscheduler"
version = "3.10.1"
description = "In-process task scheduler with Cron-like capabilities"
category = "main"
optional = false
python-versions = ">=3.6"
files = [
{file = "APScheduler-3.10.1-py3-none-any.whl", hash = "sha256:e813ad5ada7aff36fb08cdda746b520531eaac7757832abc204868ba78e0c8f6"},
{file = "APScheduler-3.10.1.tar.gz", hash = "sha256:0293937d8f6051a0f493359440c1a1b93e882c57daf0197afeff0e727777b96e"},
]
[package.dependencies]
pytz = "*"
setuptools = ">=0.7"
six = ">=1.4.0"
tzlocal = ">=2.0,<3.0.0 || >=4.0.0"
[package.extras]
doc = ["sphinx", "sphinx-rtd-theme"]
gevent = ["gevent"]
mongodb = ["pymongo (>=3.0)"]
redis = ["redis (>=3.0)"]
rethinkdb = ["rethinkdb (>=2.4.0)"]
sqlalchemy = ["sqlalchemy (>=1.4)"]
testing = ["pytest", "pytest-asyncio", "pytest-cov", "pytest-tornado5"]
tornado = ["tornado (>=4.3)"]
twisted = ["twisted"]
zookeeper = ["kazoo"]
[[package]]
name = "certifi"
version = "2022.12.7"
@ -365,33 +335,6 @@ typing-extensions = ">=4.2.0"
dotenv = ["python-dotenv (>=0.10.4)"]
email = ["email-validator (>=1.0.3)"]
[[package]]
name = "pytz"
version = "2023.3"
description = "World timezone definitions, modern and historical"
category = "main"
optional = false
python-versions = "*"
files = [
{file = "pytz-2023.3-py2.py3-none-any.whl", hash = "sha256:a151b3abb88eda1d4e34a9814df37de2a80e301e68ba0fd856fb9b46bfbbbffb"},
{file = "pytz-2023.3.tar.gz", hash = "sha256:1d8ce29db189191fb55338ee6d0387d82ab59f3d00eac103412d64e0ebd0c588"},
]
[[package]]
name = "pytz-deprecation-shim"
version = "0.1.0.post0"
description = "Shims to make deprecation of pytz easier"
category = "main"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7"
files = [
{file = "pytz_deprecation_shim-0.1.0.post0-py2.py3-none-any.whl", hash = "sha256:8314c9692a636c8eb3bda879b9f119e350e93223ae83e70e80c31675a0fdc1a6"},
{file = "pytz_deprecation_shim-0.1.0.post0.tar.gz", hash = "sha256:af097bae1b616dde5c5744441e2ddc69e74dfdcb0c263129610d85b87445a59d"},
]
[package.dependencies]
tzdata = {version = "*", markers = "python_version >= \"3.6\""}
[[package]]
name = "requests"
version = "2.29.0"
@ -418,7 +361,7 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
name = "setuptools"
version = "67.7.2"
description = "Easily download, build, install, upgrade, and uninstall Python packages"
category = "main"
category = "dev"
optional = false
python-versions = ">=3.7"
files = [
@ -431,18 +374,6 @@ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-g
testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"]
testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"]
[[package]]
name = "six"
version = "1.16.0"
description = "Python 2 and 3 compatibility utilities"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
files = [
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]
[[package]]
name = "sniffio"
version = "1.3.0"
@ -507,7 +438,7 @@ files = [
]
[package.dependencies]
greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and platform_machine == \"aarch64\" or python_version >= \"3\" and platform_machine == \"ppc64le\" or python_version >= \"3\" and platform_machine == \"x86_64\" or python_version >= \"3\" and platform_machine == \"amd64\" or python_version >= \"3\" and platform_machine == \"AMD64\" or python_version >= \"3\" and platform_machine == \"win32\" or python_version >= \"3\" and platform_machine == \"WIN32\""}
greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\")"}
[package.extras]
aiomysql = ["aiomysql", "greenlet (!=0.4.17)"]
@ -560,37 +491,6 @@ files = [
{file = "typing_extensions-4.5.0.tar.gz", hash = "sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb"},
]
[[package]]
name = "tzdata"
version = "2023.3"
description = "Provider of IANA time zone data"
category = "main"
optional = false
python-versions = ">=2"
files = [
{file = "tzdata-2023.3-py2.py3-none-any.whl", hash = "sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda"},
{file = "tzdata-2023.3.tar.gz", hash = "sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a"},
]
[[package]]
name = "tzlocal"
version = "4.3"
description = "tzinfo object for the local timezone"
category = "main"
optional = false
python-versions = ">=3.7"
files = [
{file = "tzlocal-4.3-py3-none-any.whl", hash = "sha256:b44c4388f3d34f25862cfbb387578a4d70fec417649da694a132f628a23367e2"},
{file = "tzlocal-4.3.tar.gz", hash = "sha256:3f21d09e1b2aa9f2dacca12da240ca37de3ba5237a93addfd6d593afe9073355"},
]
[package.dependencies]
pytz-deprecation-shim = "*"
tzdata = {version = "*", markers = "platform_system == \"Windows\""}
[package.extras]
devenv = ["black", "check-manifest", "flake8", "pyroma", "pytest (>=4.3)", "pytest-cov", "pytest-mock (>=3.3)", "zest.releaser"]
[[package]]
name = "urllib3"
version = "1.26.15"
@ -630,4 +530,4 @@ standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)",
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "5940b34c9293403d35f3b4df118768a86f04874bdbebba0ad30570428876cf78"
content-hash = "28f1aa3c3c4cb73bfd792180aaa8f7638002301e1391b5cdc2856acdcdeb6eb2"

View file

@ -10,12 +10,10 @@ python = "^3.10"
uvicorn = "^0.22.0"
fastapi = "^0.95.1"
requests = "^2.29.0"
apscheduler = "^3.10.1"
fastapi-utils = "^0.2.1"
[tool.poetry.scripts]
dev = "app.__main__:__main__"
[tool.poetry.group.dev.dependencies]
setuptools = "^67.7.2"
[build-system]
requires = ["poetry-core"]

View file

@ -1,4 +1,4 @@
version: "3.9"
version: "3.8"
services:
backend:
@ -6,16 +6,19 @@ services:
container_name: mootfrost-dev_backend
restart: always
build: backend/
environment:
- BIRTHDATE=2007-10-13
- HOST=0.0.0.0
frontend:
image: git.mootfrost.dev/mootfrost777/mootfrost-dev_frontend:latest
container_name: mootfrost-dev_frontend
restart: always
build: frontend/
depends_on: backend
environment:
-
depends_on:
- backend
labels:
- traefik.enable=true
- traefik.http.routers.mootfrost_dev.rule=Host(`mootfrost.dev`)
# Website port
ports:
- "7632:7632"
- "7632:3000"

3
frontend/.env Normal file
View file

@ -0,0 +1,3 @@
VITE_BACKEND=http://backend:8888
VITE
VITE_PORT=3000

View file

@ -7,6 +7,6 @@ RUN yarn install --production=true
EXPOSE 3000
COPY . .
CMD ["yarn", "dev", "--port", "3000"]
CMD ["yarn", "dev", "--port", "3000", "--host", "0.0.0.0"]

View file

@ -12,6 +12,7 @@
"@popperjs/core": "^2.11.7",
"axios": "^1.4.0",
"bootstrap": "^5.2.3",
"dotenv": "^16.0.3",
"tsparticles": "^2.9.3",
"vue": "^3.2.47",
"vue-inline-svg": "^3.1.2",

View file

@ -1,7 +1,6 @@
<script setup lang="ts">
import { loadFull } from "tsparticles";
import type { Engine } from "tsparticles-engine";
const particlesInit = async (engine: Engine) => {
await loadFull(engine);
};

View file

@ -11,7 +11,7 @@
}
async function getCodeStats() {
const resp = await axios.get<ILang[]>('http://127.0.0.1:7632/api/get_code_stats')
const resp = await axios.get<ILang[]>(`${window.location.origin}/api/v1/code_stats`)
if (resp.status !== 200) return;
if (!Object.keys(resp.data).length) {
codeStats.value = 'ничего не писал('
@ -25,7 +25,7 @@
}
async function getAge() {
const resp = await axios.get<string>('http://127.0.0.1:7632/api/get_age')
const resp = await axios.get<string>(`${window.location.origin}/api/v1/age`)
if (resp.status !== 200) return
age.value = resp.data
}

View file

@ -6,11 +6,11 @@ import IProject from "../IProject.ts";
import { ref, onMounted } from "vue";
import axios from "axios";
import.meta.env.BASE_URL
const projects = ref<IProject[]>()
onMounted(async () => {
const resp = await axios.get<IProject[]>('http://127.0.0.1:7632/api/get_repos')
const resp = await axios.get<IProject[]>(`${window.location.origin}/api/v1/repos`)
if (resp.status !== 200) return
projects.value = resp.data
console.log(projects.value)

View file

@ -1,7 +1,19 @@
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
export default defineConfig(({mode}) => {
const env = loadEnv(mode, './')
return {
plugins: [vue()],
server: {
port: +env.VITE_PORT,
proxy: {
'/api': {
target: env.VITE_BACKEND,
changeOrigin: true
}
}
}
}
})

View file

@ -389,6 +389,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
dotenv@^16.0.3:
version "16.0.3"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==
esbuild@^0.17.5:
version "0.17.18"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.18.tgz#f4f8eb6d77384d68cd71c53eb6601c7efe05e746"