Skip to content
Draft
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
130 changes: 129 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,129 @@

# DataBot Analytics — הבוט של Artisa111

זה הבוט שלי (Artisa111) לניתוח נתונים בטלגרם, יחד עם אפליקציית Streamlit להצגת דשבורדים. הפרויקט מותאם לפריסה קלה ב‑Railway, עם תצורה פשוטה, לוגים ברורים ותיעוד דו‑לשוני.

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template?template=https://github.com/Artisa111/databot-analytics&envs=TELEGRAM_TOKEN&name=DataBot%20Analytics&description=Telegram%20data%20bot%20%2B%20Streamlit)

— הערה: לאחר הפריסה, הגדירו את משתנה הסביבה TELEGRAM_TOKEN.

## מה יש כאן
- בוט טלגרם ב‑Python (Long Polling)
- אפליקציית Streamlit להצגת ניתוחים וגרפים
- פריסה פשוטה ל‑Railway עם כפתור "Deploy"
- תצורה באמצעות משתני סביבה בלבד (ללא טוקנים בקוד)

## התקנה מקומית
1) דרישות: Python 3.11+, pip

2) התקנה:
```bash
git clone https://github.com/Artisa111/databot-analytics.git
cd databot-analytics
pip install -r requirements.txt
```

3) משתני סביבה (מקומי, אופציונלי דרך .env):
```env
TELEGRAM_TOKEN=הטוקן_שלכם_מבוטפאדר
```

4) הרצה מקומית:
- בוט בלבד: `python bot_runner.py`
- Streamlit בלבד: `streamlit run app.py`
- הרצה משולבת לדמו:
```bash
sh -c "streamlit run app.py --server.port=8501 --server.address=0.0.0.0 & python bot_runner.py"
```

## פריסה ל‑Railway
- לחצו על הכפתור למעלה או חברו את הריפו אל Railway.
- הגדירו Variable בשם TELEGRAM_TOKEN עם הטוקן המדויק של הבוט.
- פקודת Start מומלצת:
```bash
sh -c "streamlit run app.py --server.port=${PORT:-8501} --server.address=0.0.0.0 & python bot_runner.py"
```

## אבטחה
- לעולם אל תתחייבו (commit) טוקנים לקוד.
- השתמשו במשתני סביבה לניהול סודות.

## מבנה הפרויקט (תקציר)
```
.
├── app.py # אפליקציית Streamlit
├── bot.py # לוגיקת הבוט וה‑handlers
├── bot_runner.py # מפעיל הבוט (Polling)
├── main.py # הרצה משולבת מקומית (בוט + Streamlit)
├── config.py # קונפיגורציה כללית
├── streamlit_app.py # מעטפת הרצה ל‑Streamlit
├── mobile_notice.py # הודעות התאמה למובייל
└── README.md
```

## קרדיט
- נכתב ומנוהל ע"י Artisa111 — זה הבוט שלי.


# DataBot Analytics — Artisa111's Bot

This is my bot (Artisa111) for Telegram data analysis, paired with a Streamlit app for visual dashboards. The project is designed for easy deployment on Railway with simple configuration and clear logs. Documentation is bilingual (Hebrew and English).

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template?template=https://github.com/Artisa111/databot-analytics&envs=TELEGRAM_TOKEN&name=DataBot%20Analytics&description=Telegram%20data%20bot%20%2B%20Streamlit)

## Features
- Telegram bot in Python (long polling)
- Streamlit app for charts and analytics
- One‑click Railway deployment
- Environment‑only secrets (no tokens in code)

## Local Setup
1) Requirements: Python 3.11+, pip

2) Install:
```bash
git clone https://github.com/Artisa111/databot-analytics.git
cd databot-analytics
pip install -r requirements.txt
```

3) Environment variables (local, via .env or system):
```env
TELEGRAM_TOKEN=your_botfather_token_here
```

4) Run locally:
- Bot only: `python bot_runner.py`
- Streamlit only: `streamlit run app.py`
- Combined (demo):
```bash
sh -c "streamlit run app.py --server.port=8501 --server.address=0.0.0.0 & python bot_runner.py"
```

## Deploy on Railway
- Click the button above or connect the repo in Railway.
- Set TELEGRAM_TOKEN in Variables.
- Recommended Start Command:
```bash
sh -c "streamlit run app.py --server.port=${PORT:-8501} --server.address=0.0.0.0 & python bot_runner.py"
```

## Security
- Never commit tokens to the repo.
- Use environment variables for secrets.

## Project Structure (short)
```
.
├── app.py
├── bot.py
├── bot_runner.py
├── main.py
├── config.py
├── streamlit_app.py
├── mobile_notice.py
└── README.md
```

## Credits
- Built and maintained by Artisa111 — this is my bot.
57 changes: 57 additions & 0 deletions docs/functions-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Function Reference — DataBot Analytics (English)

This document summarizes the core functions by module. It may not be fully exhaustive; refer to source files for the latest code.

## bot.py — Bot logic
- class DataAnalyticsBot
- __init__(self)
- Loads token from environment, builds the python-telegram-bot Application, calls setup_handlers.
- setup_handlers(self)
- Registers handlers:
- /start → start
- /help → help_command
- /analyze → analyze (if present in current version)
- /visualize → visualize (if present)
- /charts → create_charts (if present)
- Documents → handle_document
- Text → handle_text
- start(self, update, context) [async]
- Welcome message and usage instructions.
- help_command(self, update, context) [async]
- Detailed help about commands, supported files, and workflow.
- handle_document(self, update, context) [async]
- Accepts CSV/XLS/XLSX, validates extension, downloads into memory, prepares for analysis.
- handle_text(self, update, context) [async]
- Basic text interactions (greeting/help/hints for charts).
- quick_analysis(self, df, filename)
- Quick stats: rows/columns, memory, missing/duplicates, completeness; returns a ready-to-send summary.
- detailed_analysis(self, df, filename)
- Detailed numeric stats (and correlations if multiple numeric columns).

## bot_runner.py — Bot runner
- Runs the bot in long polling via `application.run_polling()`.

## main.py — Combined run (local)
- run_bot() — runs bot.py in a subprocess with colored logs.
- run_streamlit() — runs Streamlit on app.py.
- __main__ block — creates two threads (bot + Streamlit).

## app.py — Streamlit app
- main() — UI entry, configuration, navigation, and display areas.
- _db_path() → str — returns SQLite path (uploaded_data.db) for uploaded files.
- _run_sql(query: str) → pd.DataFrame — executes SQL on uploaded_data.db and returns DataFrame.
- _show_query_insights(df: pd.DataFrame) → None — compact stats + quick bar chart if small result.
- _sqlite_db_path() → str — SQLite DB path.
- _normalize_table_name(raw: str, fallback_idx: int = 1) → str — safe table name from CSV file name.
- _sqlite_run_sql(query: str) → pd.DataFrame — runs query on uploaded_data.db.

## config.py — Configuration
- TELEGRAM_TOKEN — read from os.getenv.
- PAGE_TITLE, PAGE_ICON, LAYOUT — Streamlit UI settings.
- COLORS — UI color palette.

## streamlit_app.py — Streamlit wrapper
- Loads mobile notices and executes app.py.

## mobile_notice.py — Mobile notices
- Displays mobile-related messages inside Streamlit.
57 changes: 57 additions & 0 deletions docs/functions-he.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# תיעוד פונקציות — DataBot Analytics (עברית)

המסמך מסכם את הפונקציות העיקריות לפי מודולים. ייתכן שהרשימה אינה מלאה לחלוטין (הקוד מתעדכן). ראו גם את קבצי המקור.

## bot.py — לוגיקת הבוט
- class DataAnalyticsBot
- __init__(self)
- טוען את הטוקן מהסביבה, בונה Application של python-telegram-bot, וקורא ל‑setup_handlers.
- setup_handlers(self)
- רושם את ה‑handlers לפקודות והודעות:
- /start → start
- /help → help_command
- /analyze → analyze (אם קיימת בגרסה הנוכחית)
- /visualize → visualize (אם קיימת)
- /charts → create_charts (אם קיימת)
- קבצים → handle_document
- טקסט → handle_text
- start(self, update, context) [async]
- הודעת פתיחה עם הוראות שימוש.
- help_command(self, update, context) [async]
- עזרה מפורטת על פקודות, קבצים נתמכים וזרימת עבודה.
- handle_document(self, update, context) [async]
- קבלת קבצים (CSV/XLS/XLSX), בדיקת סיומת, הורדה לזיכרון והכנה לניתוח.
- handle_text(self, update, context) [async]
- אינטראקציות טקסטואליות (ברכות, עזרה, הכוונה ליצירת גרפים).
- quick_analysis(self, df, filename)
- ניתוח מהיר: שורות/עמודות, זיכרון, חסרים/כפולים, אחוז שלמות, סיכום מוכן לשליחה.
- detailed_analysis(self, df, filename)
- ניתוח מפורט לעמודות נומריות (כולל סטטיסטיקות וקורלציות אם יש יותר מעמודה אחת).

## bot_runner.py — מפעיל הבוט
- מריץ את הבוט ב‑Long Polling דרך `application.run_polling()`.

## main.py — הרצה משולבת (מקומי)
- run_bot() — מריץ את bot.py בתהליך משנה עם לוג צבעוני.
- run_streamlit() — מריץ Streamlit על app.py.
- בלוק __main__ — יוצר שני threads, אחד לבוט ואחד ל‑Streamlit.

## app.py — אפליקציית Streamlit
- main() — כניסת UI, קונפיגורציה, ניווט ואזורי תצוגה.
- _db_path() → str — מחזיר מיקום SQLite המקומי (uploaded_data.db) לקבצים שהועלו.
- _run_sql(query: str) → pd.DataFrame — מריץ SQL על uploaded_data.db ומחזיר DataFrame.
- _show_query_insights(df: pd.DataFrame) → None — מציג סטטיסטיקות קצרות וגרף בר בהינתן תוצאה קטנה.
- _sqlite_db_path() → str — נתיב DB ל‑SQLite.
- _normalize_table_name(raw: str, fallback_idx: int = 1) → str — נרמול שם טבלה בטוח מ‑CSV.
- _sqlite_run_sql(query: str) → pd.DataFrame — מריץ שאילתה על uploaded_data.db.

## config.py — קונפיגורציה
- TELEGRAM_TOKEN — קריאה מ‑os.getenv.
- PAGE_TITLE, PAGE_ICON, LAYOUT — הגדרות עיצוב.
- COLORS — מילון צבעים לממשק.

## streamlit_app.py — מעטפת ל‑Streamlit
- טוען הודעות מובייל ומריץ את app.py.

## mobile_notice.py — הודעות מובייל
- מציג אזהרות והתאמות למובייל בתוך Streamlit.