commit bbc307f3d899cc7f9fc3c640a3d53a6e34e81acc Author: Bobby Abellana Date: Mon Feb 3 20:11:47 2025 -0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d53f6c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Virtual environments +venv/ +env/ + +# Data and reports +data/ +reports/ + +# Configuration files that contain secrets +.env + +# OS files +.DS_Store +Thumbs.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..45a61ca --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# My Stock Screener + +## Overview +This repository contains a Python-based stock screener that evaluates multiple metrics on a set of stocks, assigns a score, and outputs a CSV of the results. + +## Project Structure +- **src/** contains the main application code. +- **data/** is where you can store raw input data; it is ignored by Git. +- **reports/** is where generated CSV output is stored. + +## Setup Instructions +1. Create a virtual environment: + ```bash + python3 -m venv venv + source venv/bin/activate diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b1d86ed --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +# Basic data libraries +pandas +numpy + +# Database connector +clickhouse-connect + +# For scheduling or datetime manipulations (if needed) +python-dotenv + +# For testing +pytest diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..e69de29 diff --git a/src/db/db_connection.py b/src/db/db_connection.py new file mode 100644 index 0000000..c3e5e8c --- /dev/null +++ b/src/db/db_connection.py @@ -0,0 +1,35 @@ + +### `src/db/db_connection.py` (ClickHouse example) + +```python +import logging +import clickhouse_connect +import uuid +import time + +def create_client(clickhouse_password): + """ + Create a ClickHouse client with a unique session and retry logic. + """ + max_retries = 3 + retry_delay = 2 # seconds + for attempt in range(max_retries): + try: + client = clickhouse_connect.get_client( + host="clickhouse.abellana.work", + port=443, + username="default", + password=clickhouse_password, + secure=True, + session_id=str(uuid.uuid4()), + settings={'session_timeout': 60} + ) + # Test the connection + client.query('SELECT 1') + return client + except Exception as e: + if attempt < max_retries - 1: + logging.warning(f"Connection attempt {attempt + 1} failed: {str(e)}") + time.sleep(retry_delay) + else: + raise diff --git a/src/db/queries.py b/src/db/queries.py new file mode 100644 index 0000000..e69de29 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..e69de29 diff --git a/src/patterns/pattern_finder.py b/src/patterns/pattern_finder.py new file mode 100644 index 0000000..e69de29 diff --git a/src/screener/metrics.py b/src/screener/metrics.py new file mode 100644 index 0000000..e69de29 diff --git a/src/screener/screener.py b/src/screener/screener.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_screener.py b/tests/test_screener.py new file mode 100644 index 0000000..e69de29