Initial commit
This commit is contained in:
105
fetch_today_filings.py
Executable file
105
fetch_today_filings.py
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import argparse
|
||||
from datetime import datetime, date
|
||||
|
||||
# Check if virtual environment is activated
|
||||
if not os.environ.get('VIRTUAL_ENV'):
|
||||
print("Virtual environment is not activated.")
|
||||
print("To activate: . venv/bin/activate")
|
||||
print("Then run: python fetch_today_filings.py")
|
||||
exit(1)
|
||||
|
||||
from edgar import set_identity, get_current_filings, Company
|
||||
|
||||
# Set your identity (required by SEC)
|
||||
set_identity("your.email@example.com")
|
||||
|
||||
# Parse command-line arguments
|
||||
parser = argparse.ArgumentParser(description="Fetch latest SEC filings")
|
||||
parser.add_argument('--form', help='Form type to filter (e.g., 4, 10-K, 8-K)')
|
||||
parser.add_argument('--owner', choices=['include', 'exclude', 'only'],
|
||||
help='Owner filter: include, exclude, or only ownership filings')
|
||||
parser.add_argument('--interactive', action='store_true', help='Enter interactive mode to select filters')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Interactive mode
|
||||
if args.interactive or (args.form is None and args.owner is None):
|
||||
print("Interactive mode: Select filing filters")
|
||||
print("Available form types: 4 (insider trading), 8-K (current events), 10-K (annual reports), 10-Q (quarterly), 13G (ownership), or press Enter for all")
|
||||
form_input = input("Enter form type (or Enter for all): ").strip()
|
||||
args.form = form_input if form_input else ''
|
||||
|
||||
print("Owner filter options:")
|
||||
print("1. include - Include all filings (default)")
|
||||
print("2. exclude - Exclude ownership filings")
|
||||
print("3. only - Only ownership filings")
|
||||
owner_choice = input("Choose owner filter (1-3, default 1): ").strip()
|
||||
if owner_choice == '2':
|
||||
args.owner = 'exclude'
|
||||
elif owner_choice == '3':
|
||||
args.owner = 'only'
|
||||
else:
|
||||
args.owner = 'include'
|
||||
else:
|
||||
args.form = args.form or ''
|
||||
args.owner = args.owner or 'include'
|
||||
|
||||
def fetch_today_filings(form_filter, owner_filter):
|
||||
print(f"Fetching latest filings with form='{form_filter}', owner='{owner_filter}'...")
|
||||
|
||||
# Get current filings
|
||||
current_filings = get_current_filings(form=form_filter, owner=owner_filter)
|
||||
|
||||
if not current_filings:
|
||||
print("No current filings found.")
|
||||
return
|
||||
|
||||
# Use current filings as latest
|
||||
today_filings = current_filings
|
||||
|
||||
if not today_filings:
|
||||
print("No latest filings found.")
|
||||
return
|
||||
|
||||
print(f"Found {len(today_filings)} latest filings:")
|
||||
print("=" * 80)
|
||||
|
||||
for filing in today_filings:
|
||||
try:
|
||||
# Get entity to access ticker
|
||||
entity = filing.get_entity()
|
||||
ticker = entity.tickers[0] if hasattr(entity, 'tickers') and entity.tickers else 'N/A'
|
||||
|
||||
# For Form 4, try to get issuer's ticker if filer's ticker is N/A
|
||||
if ticker == 'N/A' and filing.form == '4':
|
||||
try:
|
||||
form4 = filing.obj()
|
||||
if form4:
|
||||
issuer = getattr(form4, 'issuer', None)
|
||||
if issuer:
|
||||
issuer_cik = getattr(issuer, 'cik', None)
|
||||
if issuer_cik:
|
||||
issuer_company = Company(issuer_cik)
|
||||
if issuer_company.tickers:
|
||||
ticker = issuer_company.tickers[0]
|
||||
except Exception:
|
||||
pass # Keep N/A if fails
|
||||
|
||||
type_of_filing = filing.form
|
||||
summary = f"{filing.form} filing by {filing.company}"
|
||||
url_link = filing.homepage_url
|
||||
|
||||
print(f"Ticker: {ticker}")
|
||||
print(f"Type: {type_of_filing}")
|
||||
print(f"Summary: {summary}")
|
||||
print(f"URL: {url_link}")
|
||||
print("-" * 40)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing filing {filing.accession_no}: {e}")
|
||||
continue
|
||||
|
||||
if __name__ == "__main__":
|
||||
fetch_today_filings(args.form, args.owner)
|
||||
Reference in New Issue
Block a user