init commit

This commit is contained in:
prod-tech
2024-11-17 02:31:42 +03:00
commit cf933c770c
217 changed files with 19340 additions and 0 deletions
View File
+66
View File
@@ -0,0 +1,66 @@
import uuid
import sqlmodel
from app.core.config import config
from app.models.user import User
engine = sqlmodel.create_engine(config.DATABASE_URL)
class UserFactory:
@staticmethod
def new_user(
id: int,
username: str,
events: list['Event'] = None,
items: list['Item'] = None,
transactions: list['Transaction'] = None,
):
with sqlmodel.Session(engine) as session:
user = User(
id=id,
username=username,
events=events if events else [],
items=items if items else [],
transactions=transactions if transactions else [],
)
session.add(user)
session.commit()
@staticmethod
def bulk_new_users(users: list[dict]):
with sqlmodel.Session(engine) as session:
print(session.exec(sqlmodel.select(User)).all())
for user in users:
UserFactory.new_user(**user)
class EventFactory:
@staticmethod
def new_event(
id: int,
owner_id: int,
invite: uuid.UUID = None,
users: list['User'] = None,
transactions: list['Transaction'] = None,
):
with sqlmodel.Session(engine) as session:
user = User(
id=id,
username=username,
events=events,
items=items,
transactions=transactions,
)
session.add(user)
session.commit()
@staticmethod
def bulk_new_users(users: list[dict]):
with sqlmodel.Session(engine) as session:
print(session.exec(sqlmodel.select(User)).all())
for user in users:
UserFactory.new_user(**user)
+28
View File
@@ -0,0 +1,28 @@
import logging
from aiohttp import ClientSession
async def get_nalog_data(ofd_string: str) -> dict:
async with ClientSession() as session:
url = 'https://proverkacheka.com/api/v1/check/get'
data = {'qrraw': ofd_string, 'token': '{{sensitive_data}}'}
response = await session.post(
url=url,
data=data,
headers={
'Content-Type': (
'application/x-www-form-urlencoded;' ' charset=UTF-8'
)
},
)
if response.status != 200:
logging.error('Received non-200 status on ofd check')
return
data = await response.json()
if data['code'] == 1:
return data
logging.error(
f'Received non-success status on ofd request with data: {data}'
)
return
+16
View File
@@ -0,0 +1,16 @@
import logging
import requests
from app.core.config import config
TELEGRAM_BOT_TOKEN = config.TOKEN_TELEGRAM_API
def send_telegram_message(chat_id: int, text: str):
url = f'https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage'
payload = {'chat_id': chat_id, 'text': text}
response = requests.post(url, json=payload)
if response.status_code != 200:
logging.error(f'Failed to send message to {chat_id}: {response.text}')