Skip to content

Commit

Permalink
added raw and text
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonfreitas committed Jul 15, 2023
1 parent ee8593e commit fe9fda0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 6 additions & 5 deletions bcb/odata/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ class EndpointQuery(ODataQuery):
def collect(self):
raw_data = super().collect()
data = pd.DataFrame(raw_data["value"])
for col in self._DATE_COLUMN_NAMES:
if self.entity.name in self._DATE_COLUMN_NAMES_BY_ENDPOINT and col in self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name]:
data[col] = pd.to_datetime(data[col], format=self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name][col])
elif col in data.columns:
data[col] = pd.to_datetime(data[col])
if not self._raw:
for col in self._DATE_COLUMN_NAMES:
if self.entity.name in self._DATE_COLUMN_NAMES_BY_ENDPOINT and col in self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name]:
data[col] = pd.to_datetime(data[col], format=self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name][col])
elif col in data.columns:
data[col] = pd.to_datetime(data[col])
return data


Expand Down
21 changes: 17 additions & 4 deletions bcb/odata/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def __init__(self, obj, order):
def __str__(self):
return f"{self.obj.name} {self.order}"

def __repr__(self):
return f"<{str(self)}>"


class ODataPropertyFilter:
def __init__(self, obj, oth, operator):
Expand All @@ -177,6 +180,9 @@ def statement(self):
def __str__(self):
return self.statement()

def __repr__(self):
return f"<filter: {str(self)}>"


class ODataProperty:
def __init__(self, **kwargs):
Expand Down Expand Up @@ -216,7 +222,7 @@ def __eq__(self, other):
return ODataPropertyFilter(self, other, "eq")

def __repr__(self):
return f"<Property {self.name}>"
return f"<Property {self.name}<{self.ftype}>>"


class ODataFunction:
Expand Down Expand Up @@ -396,6 +402,7 @@ def __init__(self, entity, url):
self._filter = []
self._select = []
self._orderby = []
self._raw = False
self.is_function = isinstance(entity, ODataFunctionImport)
if self.is_function:
self.function_parameters = {
Expand Down Expand Up @@ -450,8 +457,12 @@ def select(self, *args):
self._select.extend(args)
return self

def raw(self):
self._raw = True
return self

def _build_parameters(self):
params = {"$format": "json"}
params = {"$format": self._params.get("$format", "json")}
if len(self._filter):
_filter = " and ".join(str(f) for f in self._filter)
params["$filter"] = _filter
Expand All @@ -470,6 +481,9 @@ def reset(self):
self._params = {}

def collect(self):
return json.loads(self.text())

def text(self):
params = self._build_parameters()
if self.is_function and len(self.function_parameters):
for p in self.entity.function.parameters:
Expand All @@ -480,8 +494,7 @@ def collect(self):
qs = "&".join([f"{quote(k)}={quote(str(v))}" for k, v in params.items()])
headers = {"OData-Version": "4.0", "OData-MaxVersion": "4.0"}
res = httpx.get(self.odata_url() + "?" + qs, headers=headers, timeout=60.0)
logging.debug(res.text)
return json.loads(res.text)
return res.text

def show(self):
print(f"URL:")
Expand Down

0 comments on commit fe9fda0

Please sign in to comment.