from edgar import ( set_identity, get_filings, get_by_accession_number, Company, ) def load_identity(): set_identity("Benjamin Bascary benjamin.bascary@patagoniansys.com") load_identity() def get_latest_filings(year: int = 2024, quarter: int = 1, form: str = "NPORT-P"): """ Get the latest filings """ filings = get_filings(year, quarter, form=form) return str(filings) def get_filing_by_accession_number(accession_number: str): """ Get the filing by accession number """ filing = get_by_accession_number(accession_number) return filing def get_financials_facts_for_company(ticker_or_CIK: str): """ Get the financials for a company """ company = Company(ticker_or_CIK) return str(company.get_facts()) def get_financials_from_filing(accession_number: str): """ Get the financials from a filing that is taken from a TenK or TenQ """ filing = get_by_accession_number(accession_number) results = filing.search("company") return results def get_press_releases(ticker_or_CIK: str, num_filings: int = 5): """ Get the press releases from latest 8Ks """ company = Company(ticker_or_CIK) latest = company.get_filings(form="8-K") eightk = [x.obj() for x in latest.latest(num_filings)] with_press_releases = [x for x in eightk if x.has_press_release] press_releases = [x.press_releases for x in with_press_releases] urls = [x.attachments.get(0).url for x in press_releases] # last_press_release = press_releases[0] print(urls) return urls # print(get_latest_filings(form="10-K", year=2023)) print(get_press_releases("AAPL"))