An end-to-end data product that scrapes public Telegram channels for Ethiopian medical-related content, extracts and enriches product data using object detection (YOLO), transforms it via dbt, and serves it through an analytical API.
# Telegram Medical Analytics API
This project extracts and transforms Telegram messages and media from Ethiopian medical-related Telegram channels using dbt and Python. It supports analytics and ML use cases like object detection and sentiment analysis.
---
## β
Features
- Scrape raw Telegram messages and images
- Store unprocessed JSON files in a data lake
- Load raw data into PostgreSQL (raw schema)
- Transform data using dbt into a clean star schema:
- `dim_channels`
- `dim_dates`
- `fct_messages`
- Built-in dbt tests and documentation
---
## π Project Structure
```
telegram-medical-analytics-api/
βββ data/
β βββ raw/
β βββ telegram_messages/
β β βββ YYYY-MM-DD/
β β βββ channel_name.json
β βββ images/
β βββ channel_msgid.jpg
βββ telegram_scraping_task1.ipynb
βββ load_json_to_postgres.py
βββ telegram_dbt/
β βββ models/
β β βββ staging/
β β β βββ stg_telegram_messages.sql
β β βββ marts/
β β β βββ dim/
β β β β βββ dim_channels.sql
β β β β βββ dim_dates.sql
β β β βββ fct/
β β β βββ fct_messages.sql
β β βββ schema.yml
βββ .env
βββ .gitignore
βββ README.md
```
---
## π οΈ Setup Instructions
### 1. Virtual Environment
```bash
python -m venv env
env\Scripts\activate # Windows
```
### 2. Install Python Requirements
```bash
pip install -r requirements.txt
```
### 3. Install dbt
```bash
pip install dbt-postgres
```
### 4. Create `.env`
```env
TELEGRAM_API_ID=23786461
TELEGRAM_API_HASH=a442d356a70cb78b21df5af9a84dffb7
DB_NAME=medical_data
DB_USER=admin
DB_PASSWORD=secret
DB_HOST=localhost
DB_PORT=5432
```
---
## π§ͺ Run Scripts
### Load Raw JSON into PostgreSQL
```bash
python load_json_to_postgres.py
```
### dbt Workflow
```bash
cd telegram_dbt
dbt run
dbt test
dbt docs generate
dbt docs serve
```
---
## β
Tests in dbt
- `unique` and `not_null` on message IDs and timestamps
- Custom test: no future-dated messages
---
## π¬ Contact
For suggestions or β¦