mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
* round 1 * black * more black * providers a-thru-fmp * charting settings * charting backend * black * charting_settings * missing nasdaq import * nasdaq mypy * fed money measure * some linting * black * more linting * more linting * charting imports * black * pylint * refactor fred * more linting * rest of the providers * didn't want that file * more cleanup * missed * ta_helpers * router views * chart ta_class * forgot a file * forgot another file * biztoc * package builder * technical router * fred params * bump finviz * fix tmx * more cleanup * try again * currency historical * equity search * missed files in commit * fix some tests * black * fix more test cassettes * more patchy * black * linters * more tests * black * mypy * delete unused model * more linting * forgot files * more linting * make up your mind, black, and stop moving pylint for me * more black * back to where we were before black destroyed it * .......... * .................. * unused fetcher test * remove standard model validator * commodity router * treasury prices * oecd tests * finra * container cleanup * black * forgotten file * linter * remove wrapped "" * fix merge * patches * ecb test * finra cassette * finviz cassettes * nasdaq cassettes * oecd cassettes * yfinance cassettes * more test cassettes * black * merge cleanup * cboe helpers * black * fix typo --------- Co-authored-by: Henrique Joaquim <henriquecjoaquim@gmail.com> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""Nasdaq Helpers Module."""
|
|
|
|
|
|
def remove_html_tags(text: str):
|
|
"""Remove HTML tags from a string."""
|
|
# pylint: disable=import-outside-toplevel
|
|
import re
|
|
|
|
clean = re.compile("<.*?>")
|
|
return re.sub(clean, " ", text)
|
|
|
|
|
|
def get_random_agent() -> str:
|
|
"""Generate a random user agent for a request."""
|
|
# pylint: disable=import-outside-toplevel
|
|
from random_user_agent.user_agent import UserAgent
|
|
|
|
user_agent_rotator = UserAgent(limit=100)
|
|
user_agent = user_agent_rotator.get_random_user_agent()
|
|
return user_agent
|
|
|
|
|
|
def get_headers(accept_type: str = "json") -> dict:
|
|
"""Get the headers for the request."""
|
|
if accept_type not in ["json", "text"]:
|
|
raise ValueError("Invalid accept_type. Must be either 'json' or 'text'.")
|
|
|
|
return (
|
|
{
|
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
"Accept-Encoding": "gzip",
|
|
"Accept-Language": "en-CA,en-US;q=0.7,en;q=0.3",
|
|
"Host": "api.nasdaq.com",
|
|
"User-Agent": get_random_agent(),
|
|
"Connection": "keep-alive",
|
|
}
|
|
if accept_type == "text"
|
|
else {
|
|
"Accept": "application/json, text/plain, */*",
|
|
"Accept-Encoding": "gzip",
|
|
"Accept-Language": "en-CA,en-US;q=0.7,en;q=0.3",
|
|
"Host": "api.nasdaq.com",
|
|
"Origin": "https://www.nasdaq.com",
|
|
"Referer": "https://www.nasdaq.com/",
|
|
"User-Agent": get_random_agent(),
|
|
"Connection": "keep-alive",
|
|
}
|
|
)
|
|
|
|
|
|
def date_range(start_date, end_date):
|
|
"""Yield dates between start_date and end_date."""
|
|
# pylint: disable=import-outside-toplevel
|
|
from datetime import timedelta
|
|
|
|
for n in range(int((end_date - start_date).days) + 1):
|
|
yield start_date + timedelta(n)
|