diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e9352b0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install pytest + + - name: Run tests + run: python -m pytest tests/ -v diff --git a/.gitignore b/.gitignore index 6552aeb..0c22ee5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ __pycache__/ *.pyc -cache/ .env *.log +cache/* +!cache/.gitkeep diff --git a/README.md b/README.md index f2bb3ff..382e449 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,13 @@ docker run -p 5001:5001 10k-viewer Enter a stock ticker (e.g. `AAPL`, `MSFT`, `GOOGL`) to fetch and browse the latest 10-K filing data. Supports any company with a valid CIK identifier. +## Tests + +```bash +pip install -r requirements.txt pytest +python -m pytest tests/ +``` + ## License MIT diff --git a/app.py b/app.py index 9d2b5f1..4abb5d6 100644 --- a/app.py +++ b/app.py @@ -9,8 +9,9 @@ app = Flask(__name__) logging.basicConfig(level=logging.INFO) log = logging.getLogger("10k") -UA = "10k-viewer/1.0 (test@test.com)" +UA = "10k-viewer/1.0 (Jarian Cottingham jarianc@proton.me)" CACHE_DIR = Path(__file__).parent / "cache" +CACHE_DIR.mkdir(parents=True, exist_ok=True) MAX_RETRIES = 1 PAGE_SIZE = 10 @@ -155,9 +156,9 @@ def clean_ereader(html): t = html.decode("utf-8", errors="replace") t = re.sub(r'', '', t, flags=re.DOTALL|re.I) t = re.sub(r'', '', t, flags=re.DOTALL|re.I) - t = re.sub(r'\s+style="[^"]*"', '', t, flags=re.I) - t = re.sub(r'\s+on\w+="[^"]*"', '', t, flags=re.I) - t = re.sub(r'\s+(class|id)="[^"]*"', '', t, flags=re.I) + t = re.sub(r"""\s+style=["'][^"']*["']""", '', t, flags=re.I) + t = re.sub(r"""\s+on\w+=["'][^"']*["']""", '', t, flags=re.I) + t = re.sub(r"""\s+(class|id)=["'][^"']*["']""", '', t, flags=re.I) t = re.sub(r'', '', t, flags=re.DOTALL) s = '' if '
' in t.lower(): @@ -229,5 +230,4 @@ def view(ticker, filename): if __name__ == "__main__": - CACHE_DIR.mkdir(parents=True, exist_ok=True) app.run(host="0.0.0.0", port=5001) diff --git a/cache/.gitkeep b/cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index 7e10602..bbedbcb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -flask +flask>=3.0,<4 diff --git a/templates/archive.html b/templates/archive.html deleted file mode 100644 index d6cae89..0000000 --- a/templates/archive.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - -← Back to {{ ticker }} | All companies
-{{ archived }} of {{ total }} filings archived
-{% if failed > 0 %} -{{ failed }} failed (SEC may have rate-limited)
-{% endif %} -Files saved to local cache for offline reading.
- - diff --git a/templates/more.html b/templates/more.html deleted file mode 100644 index e051728..0000000 --- a/templates/more.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - -← Back to filings | All companies
-