initial commit
This commit is contained in:
commit
e0f4d9a855
10
Dockerfile
Normal file
10
Dockerfile
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
volumes:
|
||||||
|
- ./media:/app/media
|
||||||
|
- ./static:/app/static
|
||||||
|
- ./templates:/app/templates
|
||||||
|
environment:
|
||||||
|
- TZ=UTC
|
73
main.py
Normal file
73
main.py
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
|
from fastapi.responses import HTMLResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
from datetime import datetime
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
# Mount static and media folders
|
||||||
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||||
|
app.mount("/media", StaticFiles(directory="media"), name="media")
|
||||||
|
|
||||||
|
# Templates folder
|
||||||
|
templates = Jinja2Templates(directory="templates")
|
||||||
|
|
||||||
|
# Python's official birth date
|
||||||
|
PYTHON_BIRTH = datetime(1991, 2, 20)
|
||||||
|
|
||||||
|
|
||||||
|
class SharedState:
|
||||||
|
""" Tracks Python's current age in decimal years, updated asynchronously. """
|
||||||
|
def __init__(self):
|
||||||
|
self.current_age = 0.0
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
async def update_age(self):
|
||||||
|
""" Continuously update Python's age in decimal years. """
|
||||||
|
while self.running:
|
||||||
|
now = datetime.now()
|
||||||
|
delta = now - PYTHON_BIRTH
|
||||||
|
# Convert time delta to decimal years
|
||||||
|
self.current_age = delta.days / 365.25 + (delta.seconds / (86400 * 365.25))
|
||||||
|
await asyncio.sleep(0.1) # Update about 10 times per second
|
||||||
|
|
||||||
|
|
||||||
|
state = SharedState()
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def on_startup():
|
||||||
|
state.running = True
|
||||||
|
asyncio.create_task(state.update_age())
|
||||||
|
|
||||||
|
@app.on_event("shutdown")
|
||||||
|
async def on_shutdown():
|
||||||
|
state.running = False
|
||||||
|
|
||||||
|
@app.get("/", response_class=HTMLResponse)
|
||||||
|
async def home(request: Request):
|
||||||
|
"""
|
||||||
|
Main page with an <object> that loads /stream.
|
||||||
|
"""
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
"index.html",
|
||||||
|
{
|
||||||
|
"request": request,
|
||||||
|
"now": datetime.now()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@app.get("/stream", response_class=HTMLResponse)
|
||||||
|
async def stream_time(request: Request):
|
||||||
|
"""
|
||||||
|
Returns a tiny HTML snippet that self-refreshes every 0.1 seconds.
|
||||||
|
No leftover lines, no JS. The page is simply reloaded repeatedly.
|
||||||
|
"""
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
"counter.html",
|
||||||
|
{
|
||||||
|
"request": request,
|
||||||
|
"current_age": f"{state.current_age:.10f}"
|
||||||
|
}
|
||||||
|
)
|
BIN
media/meme1.jpg
Normal file
BIN
media/meme1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
media/meme2.png
Normal file
BIN
media/meme2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 285 KiB |
5
requirements.txt
Normal file
5
requirements.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fastapi==0.109.1
|
||||||
|
uvicorn==0.27.0
|
||||||
|
jinja2==3.1.3
|
||||||
|
python-multipart==0.0.7
|
||||||
|
aiofiles==23.2.1
|
2
static/python.svg
Normal file
2
static/python.svg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||||
|
<svg width="800px" height="800px" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M31.885 16c-8.124 0-7.617 3.523-7.617 3.523l.01 3.65h7.752v1.095H21.197S16 23.678 16 31.876c0 8.196 4.537 7.906 4.537 7.906h2.708v-3.804s-.146-4.537 4.465-4.537h7.688s4.32.07 4.32-4.175v-7.019S40.374 16 31.885 16zm-4.275 2.454c.771 0 1.395.624 1.395 1.395s-.624 1.395-1.395 1.395a1.393 1.393 0 0 1-1.395-1.395c0-.771.624-1.395 1.395-1.395z" fill="url(#a)"/><path d="M32.115 47.833c8.124 0 7.617-3.523 7.617-3.523l-.01-3.65H31.97v-1.095h10.832S48 40.155 48 31.958c0-8.197-4.537-7.906-4.537-7.906h-2.708v3.803s.146 4.537-4.465 4.537h-7.688s-4.32-.07-4.32 4.175v7.019s-.656 4.247 7.833 4.247zm4.275-2.454a1.393 1.393 0 0 1-1.395-1.395c0-.77.624-1.394 1.395-1.394s1.395.623 1.395 1.394c0 .772-.624 1.395-1.395 1.395z" fill="url(#b)"/><defs><linearGradient id="a" x1="19.075" y1="18.782" x2="34.898" y2="34.658" gradientUnits="userSpaceOnUse"><stop stop-color="#387EB8"/><stop offset="1" stop-color="#366994"/></linearGradient><linearGradient id="b" x1="28.809" y1="28.882" x2="45.803" y2="45.163" gradientUnits="userSpaceOnUse"><stop stop-color="#FFE052"/><stop offset="1" stop-color="#FFC331"/></linearGradient></defs></svg>
|
After Width: | Height: | Size: 1.3 KiB |
24
templates/counter.html
Normal file
24
templates/counter.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="refresh" content="0.5" />
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<style>
|
||||||
|
.counter {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
font-family: 'Segoe UI', monospace;
|
||||||
|
font-size: clamp(1rem, 3vw, 2rem);
|
||||||
|
height: 80px;
|
||||||
|
overflow: hidden;
|
||||||
|
color: #3776AB;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="counter">
|
||||||
|
ПИТОН ПОБЕДА УЖЕ {{ current_age }} ЛЕТ
|
||||||
|
</body>
|
||||||
|
</html>
|
146
templates/index.html
Normal file
146
templates/index.html
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>ПИТОН ПОБЕДА</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--python-blue: #3776AB;
|
||||||
|
--python-yellow: #FFD43B;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe UI', Arial, sans-serif;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
color: var(--python-blue);
|
||||||
|
font-size: clamp(1.5rem, 4vw, 2.5rem);
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||||
|
gap: 2rem;
|
||||||
|
margin: 2rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.python-facts {
|
||||||
|
background-color: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 1.5rem;
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
margin: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fact-item {
|
||||||
|
margin: 1rem 0;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-radius: 8px;
|
||||||
|
border-left: 4px solid var(--python-blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container {
|
||||||
|
margin: 20px auto;
|
||||||
|
max-width: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meme-container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
margin: 2rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meme-image {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinning-logo {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
animation: spin 10s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
from { transform: rotate(0deg); }
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
#counter-frame {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 600px;
|
||||||
|
height: 80px;
|
||||||
|
border: none;
|
||||||
|
margin: 20px auto;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
margin-top: auto;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: var(--python-blue);
|
||||||
|
color: white;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
body {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meme-container {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>{{ now.year }} - ГОД ОЧЕРЕДНОЙ ПИТОН ПОБЕДЫ 🐍</h1>
|
||||||
|
|
||||||
|
<object id="counter-frame" data="/stream"></object>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="python-facts">
|
||||||
|
|
||||||
|
<div class="image-container">
|
||||||
|
<img src="/static/python.svg" alt="Python Logo" class="spinning-logo">
|
||||||
|
</div>
|
||||||
|
<h2>Почему 2025 это год Питона?</h2>
|
||||||
|
<div class="fact-item">💻 Python программисты пишут код быстрее, чем JavaScript его интерпретирует</div>
|
||||||
|
<div class="fact-item">🐍 У нас есть настоящие лямбды, а не эти ваши "=>"</div>
|
||||||
|
<div class="fact-item">⚡️ Мутируемые дефолтные аргументы? Это не баг, а фича!</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="meme-container">
|
||||||
|
<img src="/media/meme1.jpg" alt="Python Meme 1" class="meme-image">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
Работает на FastAPI - Без JavaScript! 🚀
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
<!-- creds: санспай.рф -->
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user