Работа с БД
This commit is contained in:
parent
003ccabeda
commit
8dfa4d0177
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
/keys/
|
/keys/
|
||||||
*.pem
|
*.pem
|
||||||
/output.txt
|
/output.txt
|
||||||
|
/.env
|
||||||
|
4
app.py
4
app.py
@ -1,5 +1,4 @@
|
|||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException
|
||||||
from pydantic import BaseModel
|
|
||||||
from typing import List, Optional, Dict
|
from typing import List, Optional, Dict
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@ -36,4 +35,5 @@ def get_item(license_key: str):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
uvicorn.run(app, host='127.0.0.1', port=8000)
|
# uvicorn.run("app:app", host='127.0.0.1', port=8000, workers=4)
|
||||||
|
uvicorn.run("app:app", host='127.0.0.1', port=8000, reload=True)
|
||||||
|
25
db.py
25
db.py
@ -1,22 +1,19 @@
|
|||||||
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import sql
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# Настройки подключения
|
load_dotenv()
|
||||||
host = "localhost"
|
|
||||||
port = "5432"
|
table_name = 'licenses'
|
||||||
user = "postgres"
|
|
||||||
password = "postgres"
|
|
||||||
database_name = "postgres"
|
|
||||||
table_name = "licenses"
|
|
||||||
|
|
||||||
|
|
||||||
def connect_to_database():
|
def connect_to_database():
|
||||||
connection = psycopg2.connect(
|
connection = psycopg2.connect(
|
||||||
host=host,
|
host=os.getenv('db_host'),
|
||||||
port=port,
|
port=os.getenv('db_port'),
|
||||||
user=user,
|
user=os.getenv('db_user'),
|
||||||
password=password,
|
password=os.getenv('db_password'),
|
||||||
database=database_name
|
database=os.getenv('db_name')
|
||||||
)
|
)
|
||||||
return connection, connection.cursor()
|
return connection, connection.cursor()
|
||||||
|
|
||||||
@ -33,7 +30,7 @@ class LicenseDatabase:
|
|||||||
owner_license VARCHAR(255) NOT NULL,
|
owner_license VARCHAR(255) NOT NULL,
|
||||||
expiration_date DATE NOT NULL,
|
expiration_date DATE NOT NULL,
|
||||||
device_count INT NOT NULL,
|
device_count INT NOT NULL,
|
||||||
license_key VARCHAR(500) -- Добавлена запятая здесь
|
license_key VARCHAR(500)
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
self.cursor.execute(create_table_query)
|
self.cursor.execute(create_table_query)
|
||||||
|
58
requirements.ini
Normal file
58
requirements.ini
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
annotated-types==0.7.0
|
||||||
|
anyio==4.8.0
|
||||||
|
backports.tarfile==1.2.0
|
||||||
|
build==1.2.2.post1
|
||||||
|
CacheControl==0.14.0
|
||||||
|
certifi==2024.8.30
|
||||||
|
cffi==1.16.0
|
||||||
|
charset-normalizer==3.3.0
|
||||||
|
cleo==2.1.0
|
||||||
|
click==8.1.8
|
||||||
|
crashtest==0.4.1
|
||||||
|
cryptography==41.0.4
|
||||||
|
distlib==0.3.8
|
||||||
|
dulwich==0.22.7
|
||||||
|
fastapi==0.115.11
|
||||||
|
fastjsonschema==2.18.1
|
||||||
|
filelock==3.16.1
|
||||||
|
findpython==0.6.2
|
||||||
|
h11==0.14.0
|
||||||
|
httpcore==1.0.7
|
||||||
|
httpx==0.28.1
|
||||||
|
idna==3.4
|
||||||
|
importlib-metadata==6.8.0
|
||||||
|
installer==0.7.0
|
||||||
|
jaraco.classes==3.3.0
|
||||||
|
jaraco.context==6.0.1
|
||||||
|
jaraco.functools==4.1.0
|
||||||
|
jeepney==0.8.0
|
||||||
|
keyring==25.6.0
|
||||||
|
more-itertools==10.1.0
|
||||||
|
msgpack==1.0.7
|
||||||
|
packaging==24.1
|
||||||
|
pbs-installer==2025.2.12
|
||||||
|
pipenv==2024.4.1
|
||||||
|
pkginfo==1.12.0
|
||||||
|
platformdirs==4.3.6
|
||||||
|
poetry==2.1.1
|
||||||
|
poetry-core==2.1.1
|
||||||
|
psycopg2-binary==2.9.10
|
||||||
|
pycparser==2.21
|
||||||
|
pydantic==2.10.6
|
||||||
|
pydantic_core==2.27.2
|
||||||
|
pyproject_hooks==1.0.0
|
||||||
|
rapidfuzz==3.5.2
|
||||||
|
requests==2.31.0
|
||||||
|
requests-toolbelt==1.0.0
|
||||||
|
SecretStorage==3.3.3
|
||||||
|
shellingham==1.5.3
|
||||||
|
sniffio==1.3.1
|
||||||
|
starlette==0.46.0
|
||||||
|
tomlkit==0.12.1
|
||||||
|
trove-classifiers==2023.9.19
|
||||||
|
typing_extensions==4.12.2
|
||||||
|
urllib3==2.0.6
|
||||||
|
uvicorn==0.34.0
|
||||||
|
virtualenv==20.29.2
|
||||||
|
zipp==3.17.0
|
||||||
|
zstandard==0.23.0
|
@ -55,3 +55,6 @@ uvicorn==0.34.0
|
|||||||
virtualenv==20.29.2
|
virtualenv==20.29.2
|
||||||
zipp==3.17.0
|
zipp==3.17.0
|
||||||
zstandard==0.23.0
|
zstandard==0.23.0
|
||||||
|
|
||||||
|
psycopg2-binary~=2.9.10
|
||||||
|
python-dotenv~=1.0.1
|
Loading…
Reference in New Issue
Block a user