-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support exact search with quotes in the notebook (#33)
* Remove sys.exit from cli.py * Convert notebook to handle exceptions rather than sys exit * Bump version
- Loading branch information
1 parent
97b60fd
commit b6cb1a6
Showing
3 changed files
with
48 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ | |
"from ipywidgets import widgets\n", | ||
"from IPython.display import display\n", | ||
"from IPython import get_ipython\n", | ||
"from contextlib import redirect_stdout\n", | ||
"\n", | ||
"data_table.enable_dataframe_formatter()\n", | ||
"\n", | ||
|
@@ -74,33 +75,41 @@ | |
"\n", | ||
"# Install the EDGAR search tool on the first run\n", | ||
"![ ! -f \"edgar_tool_installed\" ] && echo -n \"Loading the EDGAR Tool on first search...\" && pip install edgar-tool >> {logfile} 2>&1 && pip install pandas==1.5.3 >> {logfile} 2>&1 && touch edgar_tool_installed && echo \"Loaded.\"\n", | ||
"from edgar_tool.cli import SecEdgarScraperCli as edgar_tool\n", | ||
"from edgar_tool.page_fetcher import NoResultsFoundError\n", | ||
"\n", | ||
"# Run the tool with the query\n", | ||
"!echo -n \"Searching EDGAR...\"\n", | ||
"!edgar-tool text_search {search_keywords} --start_date {start_date} --end_date {end_date} --filing_form {filing_type} --entity_id {company_cik} --output {output} --browser firefox --min-wait 0.5 --max-wait 1.5 {loc_filter} >> {logfile} 2>&1\n", | ||
"exit_code = get_ipython().__dict__['user_ns']['_exit_code']\n", | ||
"!echo \"Done.\"\n", | ||
"\n", | ||
"# Error handling\n", | ||
"if exit_code == 2:\n", | ||
"print(\"Searching EDGAR...\")\n", | ||
"try:\n", | ||
" with open(logfile, 'a') as f:\n", | ||
" with redirect_stdout(f):\n", | ||
" edgar_tool.text_search(\n", | ||
" search_keywords,\n", | ||
" start_date=start_date, \n", | ||
" end_date=end_date,\n", | ||
" filing_form=filing_type,\n", | ||
" entity_id=company_cik,\n", | ||
" output=output,\n", | ||
" peo_in=location if filter_by_location==\"Principal executive offices in\" else None,\n", | ||
" inc_in=location if filter_by_location==\"Incorporated in\" else None,\n", | ||
" )\n", | ||
" print(\"Done.\")\n", | ||
" # Load results\n", | ||
" results = pd.read_csv(output)\n", | ||
"\n", | ||
" # Show download button\n", | ||
" btn = widgets.Button(description='Download Results')\n", | ||
" btn.on_click(lambda x: files.download(output))\n", | ||
" display(btn)\n", | ||
"\n", | ||
" # Display the results in a data table\n", | ||
" display(results)\n", | ||
"except NoResultsFoundError:\n", | ||
" print(\"\\x1b[33m No results were found for your query.\\x1b[0m\")\n", | ||
"elif exit_code != 0:\n", | ||
" print(\"\\x1b[31m Something went wrong with the EDGAR tool, check your search and try again.\\x1b[0m\")\n", | ||
"else:\n", | ||
" try:\n", | ||
" # Load results\n", | ||
" results = pd.read_csv(output)\n", | ||
"\n", | ||
" # Show download button\n", | ||
" btn = widgets.Button(description='Download Results')\n", | ||
" btn.on_click(lambda x: files.download(output))\n", | ||
" display(btn)\n", | ||
"\n", | ||
" # Display the results in a data table\n", | ||
" display(results)\n", | ||
" except FileNotFoundError as e:\n", | ||
" print(\"\\x1b[31m Something went wrong with the EDGAR tool, please get in touch at [email protected] and help us improve the tool for everyone. \\x1b[0m\")\n", | ||
"\n" | ||
"except FileNotFoundError as e:\n", | ||
" print(\"\\x1b[31m Something went wrong with the EDGAR tool, please get in touch at [email protected] and help us improve the tool for everyone. \\x1b[0m\")\n", | ||
"except Exception as e:\n", | ||
" print(\"\\x1b[31m Something went wrong with the EDGAR tool, check your search and try again.\\x1b[0m\") " | ||
] | ||
} | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters