mirror of
https://github.com/marcogll/telegram_expenses_controller.git
synced 2026-01-13 13:25:15 +00:00
feat: Implement core application structure, AI extraction, persistence, and Telegram bot modules with updated configuration and dependencies.
This commit is contained in:
0
app/integrations/__init__.py
Normal file
0
app/integrations/__init__.py
Normal file
23
app/integrations/exporters.py
Normal file
23
app/integrations/exporters.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Functions for exporting data to other formats or systems (e.g., CSV, Google Sheets).
|
||||
"""
|
||||
import csv
|
||||
import io
|
||||
from typing import List
|
||||
from app.schema.base import FinalExpense
|
||||
|
||||
def export_to_csv(expenses: List[FinalExpense]) -> str:
|
||||
"""
|
||||
Exports a list of expenses to a CSV formatted string.
|
||||
"""
|
||||
output = io.StringIO()
|
||||
writer = csv.writer(output)
|
||||
|
||||
# Write header
|
||||
writer.writerow(FinalExpense.__fields__.keys())
|
||||
|
||||
# Write data
|
||||
for expense in expenses:
|
||||
writer.writerow(expense.dict().values())
|
||||
|
||||
return output.getvalue()
|
||||
21
app/integrations/webhook_client.py
Normal file
21
app/integrations/webhook_client.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
Client for sending data to external webhook URLs.
|
||||
"""
|
||||
import httpx
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def send_to_webhook(url: str, data: dict):
|
||||
"""
|
||||
Sends a POST request with JSON data to a specified webhook URL.
|
||||
"""
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(url, json=data)
|
||||
response.raise_for_status()
|
||||
logger.info(f"Successfully sent data to webhook {url}")
|
||||
return True
|
||||
except httpx.RequestError as e:
|
||||
logger.error(f"Failed to send data to webhook {url}: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user