mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-25 10:42:58 +00:00
* Relink sdk/sdk -> platform/platform * Relink sdk -> platform * Rename folders * Fix dev_install script * Fix test generators * Fix test generators * Fix test generators * Organize imports
26 lines
769 B
Python
26 lines
769 B
Python
"""Benzinga Helpers."""
|
|
|
|
|
|
from typing import Any, Dict
|
|
|
|
from openbb_provider import helpers
|
|
|
|
|
|
def get_data(url: str, **kwargs: Any) -> Dict:
|
|
"""Do an API request to Benzinga and return the data."""
|
|
result = helpers.make_request(
|
|
url, timeout=10, headers={"accept": "application/json"}, **kwargs
|
|
)
|
|
if result.status_code != 200:
|
|
data = result.json()
|
|
if data == ['Access denied for user 0 "anonymous"']:
|
|
raise RuntimeError("API Key is invalid")
|
|
if len(data) == 0:
|
|
raise RuntimeError("No news found!")
|
|
message = data.get("message")
|
|
error = data.get("error")
|
|
value = message or error
|
|
raise RuntimeError(f"Error in Benzinga request -> {value}")
|
|
|
|
return result.json()
|