kopia lustrzana https://github.com/bugout-dev/moonstream
Download query results data endpoint
rodzic
b2e598e0f8
commit
c8f4d4efdc
|
@ -10,6 +10,7 @@ from .data import (
|
||||||
MoonstreamQueries,
|
MoonstreamQueries,
|
||||||
MoonstreamQuery,
|
MoonstreamQuery,
|
||||||
MoonstreamQueryResultUrl,
|
MoonstreamQueryResultUrl,
|
||||||
|
OutputType,
|
||||||
)
|
)
|
||||||
from .exceptions import MoonstreamResponseException, MoonstreamUnexpectedResponse
|
from .exceptions import MoonstreamResponseException, MoonstreamUnexpectedResponse
|
||||||
from .settings import MOONSTREAM_API_URL, MOONSTREAM_REQUEST_TIMEOUT
|
from .settings import MOONSTREAM_API_URL, MOONSTREAM_REQUEST_TIMEOUT
|
||||||
|
@ -198,6 +199,30 @@ class Moonstream:
|
||||||
|
|
||||||
return MoonstreamQueryResultUrl(url=response["url"])
|
return MoonstreamQueryResultUrl(url=response["url"])
|
||||||
|
|
||||||
|
def download_query_results(
|
||||||
|
self,
|
||||||
|
url: str,
|
||||||
|
output_type: OutputType = OutputType.JSON,
|
||||||
|
timeout: float = MOONSTREAM_REQUEST_TIMEOUT,
|
||||||
|
**kwargs,
|
||||||
|
) -> Any:
|
||||||
|
"""
|
||||||
|
Fetch results of query from url.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
response = requests.request(
|
||||||
|
Method.GET.value, url=url, timeout=timeout, **kwargs
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(str(e))
|
||||||
|
|
||||||
|
output = response
|
||||||
|
if output_type == OutputType.JSON:
|
||||||
|
output = response.json()
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
def delete_query(
|
def delete_query(
|
||||||
self,
|
self,
|
||||||
token: Union[str, uuid.UUID],
|
token: Union[str, uuid.UUID],
|
||||||
|
|
|
@ -23,6 +23,11 @@ class Method(Enum):
|
||||||
PUT = "put"
|
PUT = "put"
|
||||||
|
|
||||||
|
|
||||||
|
class OutputType(Enum):
|
||||||
|
CSV = "csv"
|
||||||
|
JSON = "json"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class MoonstreamQuery:
|
class MoonstreamQuery:
|
||||||
id: uuid.UUID
|
id: uuid.UUID
|
||||||
|
|
Ładowanie…
Reference in New Issue