Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,6 @@ test_json/
logs/json/
logs/temp/
logs/usage/
*.ignore.*
*.ignore.*
a.json
a.py
2 changes: 1 addition & 1 deletion conf/config_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AppConfig:
sentry: SentryConfig
otel: OTELConfig
environment: str = "development"
mongo: UsageCollectionMongoConfig = UsageCollectionMongoConfig()
mongo: UsageCollectionMongoConfig | None = None


def New() -> AppConfig:
Expand Down
15 changes: 7 additions & 8 deletions conf/logger_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,21 @@ def setup_logging(logfile: str) -> structlog.stdlib.BoundLogger:

# --- 1. Create handlers ---
console_handler = logging.StreamHandler(sys.stdout)
log_level = logging.DEBUG
if os.getenv("ENVIRONMENT", "development").lower() == "development":
console_handler.setLevel(logging.INFO)
log_level = logging.DEBUG
else:
console_handler.setLevel(logging.INFO)
log_level = logging.INFO
console_handler.setLevel(log_level)
console_handler.setFormatter(logging.Formatter(fmt="%(message)s"))

file_handler = logging.FileHandler(logfile)
if os.getenv("ENVIRONMENT", "development").lower() == "development":
file_handler.setLevel(logging.INFO)
else:
file_handler.setLevel(logging.DEBUG)
file_handler.setLevel(log_level)
file_handler.setFormatter(logging.Formatter(fmt="%(message)s"))

# --- 2. Set up root logger ---
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.setLevel(log_level)
root_logger.handlers = [] # clear default handlers
root_logger.addHandler(console_handler)
root_logger.addHandler(file_handler)
Expand All @@ -57,7 +56,7 @@ def setup_logging(logfile: str) -> structlog.stdlib.BoundLogger:
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.make_filtering_bound_logger(logging.DEBUG),
wrapper_class=structlog.make_filtering_bound_logger(log_level),
cache_logger_on_first_use=True,
)

Expand Down
2 changes: 2 additions & 0 deletions functions_to_format/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
get_suppliers_by_category,
get_number_by_receiver_name,
send_money_to_someone_via_card,
pay_for_home_utility,
)
from .contact import build_contact_widget, get_contact
from .news import build_news_widget, get_news
Expand Down Expand Up @@ -52,4 +53,5 @@
"send_money_to_someone_via_card": send_money_to_someone_via_card,
"get_home_balances": get_home_balances,
"build_contacts_list": build_contacts_list,
"pay_for_home_utility": pay_for_home_utility,
}
2 changes: 1 addition & 1 deletion functions_to_format/functions/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def build_balance_ui(
margins=dv.DivEdgeInsets(bottom=8),
)
)
main_items.extend([card_block(c) for c in cards])
main_items.extend([card_block(c, language) for c in cards])

# Сообщение и кнопки
# main_items.append(
Expand Down
2 changes: 1 addition & 1 deletion functions_to_format/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def build_contacts_list(context) -> BuildOutput:
),
build_buttons_row: WidgetInput(
widget=buttons,
args={"button_texts": ["cancel"]},
args={"button_texts": ["cancel"], "language": language},
),
# build_text_widget: WidgetInput(
# widget=text_widget,
Expand Down
17 changes: 11 additions & 6 deletions functions_to_format/functions/general/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .buttons import build_buttons_row, ButtonsWidget
from models.widget import Widget
from pydantic import BaseModel
from conf import logger


class WidgetInput(BaseModel):
Expand All @@ -16,13 +17,17 @@ def add_ui_to_widget(
):
if version == "v3":
for sdui_function, widget_input in widget_inputs.items():
if (
sdui_function.__name__ == "build_text_widget"
and len(widget_input.args["text"]) == 0
):
try:
if (
sdui_function.__name__ == "build_text_widget"
and len(widget_input.args["text"]) == 0
):
continue
widget_args = widget_input.args
widget_input.widget.build_ui(sdui_function, **widget_args)
except Exception as e:
logger.exception("Error building widget", error=e)
continue
widget_args = widget_input.args
widget_input.widget.build_ui(sdui_function, **widget_args)
widgets: List[Widget] = []
for widget_input in widget_inputs.values():
widgets.append(widget_input.widget)
Expand Down
34 changes: 29 additions & 5 deletions functions_to_format/functions/general/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from models.widget import Widget
from .const_values import WidgetMargins, WidgetPaddings, ButtonInRowMargins
from .const_values import LanguageOptions


class ButtonsWidget(Widget):
Expand All @@ -25,7 +26,7 @@ def make_contacts_search_button(txt, receiver_name):
payload={"name": [receiver_name]}, # Optional: structured access
)
return dv.DivText(
text="Qidirish",
text=txt,
font_size=14,
text_color="#2563EB",
border=dv.DivBorder(corner_radius=8, stroke=dv.DivStroke(color="#3B82F6")),
Expand All @@ -42,15 +43,38 @@ def make_contacts_search_button(txt, receiver_name):
)


def build_buttons_row(button_texts: list, receiver_name: str | None = None):
def build_buttons_row(
button_texts: list,
receiver_name: str | None = None,
language: LanguageOptions = LanguageOptions.RUSSIAN,
):
items = []

texts_map = {
LanguageOptions.RUSSIAN: {
"search": "Поиск",
"cancel": "Отмена",
},
LanguageOptions.ENGLISH: {
"search": "Search",
"cancel": "Cancel",
},
LanguageOptions.UZBEK: {
"search": "Qidirish",
"cancel": "Bekor qilish",
},
}

for txt in button_texts:
if txt == "search":
items.append(make_contacts_search_button(txt, receiver_name))
items.append(
make_contacts_search_button(texts_map[language][txt], receiver_name)
)

else:
items.append(
dv.DivText(
text=txt,
text=texts_map[language][txt],
font_size=14,
text_color="#2563EB",
border=dv.DivBorder(
Expand Down Expand Up @@ -84,7 +108,7 @@ def build_buttons_row(button_texts: list, receiver_name: str | None = None):
),
)
)
with open("logs/build_buttons.json", "w") as f:
with open("logs/json/build_buttons.json", "w") as f:
json.dump(div, f, indent=2, ensure_ascii=False)
return div

Expand Down
8 changes: 3 additions & 5 deletions functions_to_format/functions/general/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,16 @@ async def load_usages_async(collection: AsyncCollection, file_path: str):
else:
await collection.insert_one(usage)

logger.debug(f"Usage uploaded: {request_id}")

except Exception as e:
logger.error(f"Error loading usages: {e}")


async def upload_usages_async() -> None:
try:
client = AsyncMongoClient(config.mongo.mongo_uri)
client = AsyncMongoClient(config.mongo.mongo_uri) # pyright: ignore[reportOptionalMemberAccess]
collection: AsyncCollection = client.get_database(
config.mongo.database_name
).get_collection(config.mongo.collection_name)
config.mongo.database_name # pyright: ignore[reportOptionalMemberAccess]
).get_collection(config.mongo.collection_name) # pyright: ignore[reportOptionalMemberAccess]
tasks = []
for file in os.listdir("logs/usage"):
tasks.append(load_usages_async(collection, f"logs/usage/{file}"))
Expand Down
Loading