| |
|
| | """
|
| | Test script for SEC EDGAR integration
|
| | This script tests the SEC API functionality without running the full Gradio interface
|
| | """
|
| |
|
| | import sys
|
| | import os
|
| |
|
| |
|
| | sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| |
|
| | from gradio_stock_dashboard import SECEdgarAPI, CompanyInfo, StockDashboard
|
| |
|
| | def test_sec_api():
|
| | """Test basic SEC API functionality"""
|
| | print("π§ͺ Testing SEC EDGAR API Integration...")
|
| | print("=" * 50)
|
| |
|
| |
|
| | sec_api = SECEdgarAPI()
|
| | print("β SEC API class initialized")
|
| |
|
| |
|
| | test_ticker = "AAPL"
|
| | print(f"\nπ± Testing company info for {test_ticker}...")
|
| |
|
| | company_info = CompanyInfo(test_ticker)
|
| | cik = company_info.get_cik_from_ticker()
|
| |
|
| | if cik:
|
| | print(f"β Found CIK: {cik}")
|
| | print(f"β Company Name: {company_info.company_name}")
|
| |
|
| |
|
| | print(f"\nπ Testing SEC filings retrieval for {test_ticker}...")
|
| | filings = company_info.fetch_sec_filings(sec_api)
|
| |
|
| | if filings:
|
| | print(f"β Found {len(filings)} filings")
|
| | print("Sample filings:")
|
| | for i, filing in enumerate(filings[:3]):
|
| | print(f" {i+1}. {filing.get('form', 'Unknown')} - {filing.get('filingDate', 'Unknown')}")
|
| | if filing.get('filingUrl'):
|
| | print(f" URL: {filing['filingUrl']}")
|
| | else:
|
| | print("β No filings found")
|
| |
|
| |
|
| | print(f"\nπ° Testing financial metrics for {test_ticker}...")
|
| | dashboard = StockDashboard()
|
| | metrics, status = dashboard.get_key_financial_metrics(test_ticker)
|
| |
|
| | if metrics:
|
| | print(f"β Found {len(metrics)} financial metrics")
|
| | for metric_name, metric_data in metrics.items():
|
| | value = metric_data.get('value', 'N/A')
|
| | date = metric_data.get('date', 'Unknown')
|
| | print(f" {metric_name}: {value} (as of {date})")
|
| | else:
|
| | print(f"β No financial metrics found: {status}")
|
| |
|
| | else:
|
| | print(f"β Could not find CIK for {test_ticker}")
|
| |
|
| | print("\n" + "=" * 50)
|
| | print("π― Test completed!")
|
| |
|
| | def test_multiple_companies():
|
| | """Test SEC functionality with multiple companies"""
|
| | print("\nπ§ͺ Testing Multiple Companies...")
|
| | print("=" * 50)
|
| |
|
| | dashboard = StockDashboard()
|
| | test_tickers = ["AAPL", "MSFT", "GOOGL"]
|
| |
|
| | print(f"Testing SEC filings for: {', '.join(test_tickers)}")
|
| |
|
| |
|
| | filings, status = dashboard.get_sec_filings_for_companies(test_tickers)
|
| | print(f"\nπ SEC Filings: {status}")
|
| |
|
| | if filings:
|
| | print(f"Total filings found: {len(filings)}")
|
| |
|
| |
|
| | by_company = {}
|
| | for filing in filings:
|
| | ticker = filing.get('ticker', 'Unknown')
|
| | if ticker not in by_company:
|
| | by_company[ticker] = []
|
| | by_company[ticker].append(filing)
|
| |
|
| | for ticker, company_filings in by_company.items():
|
| | print(f"\n{ticker}: {len(company_filings)} filings")
|
| | for filing in company_filings[:2]:
|
| | print(f" - {filing.get('form', 'Unknown')} ({filing.get('filingDate', 'Unknown')})")
|
| |
|
| |
|
| | print(f"\nπ° Testing Financial Metrics...")
|
| | metrics_table, status = dashboard.create_financial_metrics_table(test_tickers)
|
| | print(f"Financial Metrics: {status}")
|
| |
|
| | print("\n" + "=" * 50)
|
| | print("π― Multiple companies test completed!")
|
| |
|
| | if __name__ == "__main__":
|
| | try:
|
| | test_sec_api()
|
| | test_multiple_companies()
|
| | print("\nβ
All tests completed successfully!")
|
| |
|
| | except Exception as e:
|
| | print(f"\nβ Test failed with error: {e}")
|
| | import traceback
|
| | traceback.print_exc()
|
| |
|