Skip to content

Commit fe9fda0

Browse files
committed
added raw and text
1 parent ee8593e commit fe9fda0

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

bcb/odata/api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ class EndpointQuery(ODataQuery):
4444
def collect(self):
4545
raw_data = super().collect()
4646
data = pd.DataFrame(raw_data["value"])
47-
for col in self._DATE_COLUMN_NAMES:
48-
if self.entity.name in self._DATE_COLUMN_NAMES_BY_ENDPOINT and col in self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name]:
49-
data[col] = pd.to_datetime(data[col], format=self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name][col])
50-
elif col in data.columns:
51-
data[col] = pd.to_datetime(data[col])
47+
if not self._raw:
48+
for col in self._DATE_COLUMN_NAMES:
49+
if self.entity.name in self._DATE_COLUMN_NAMES_BY_ENDPOINT and col in self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name]:
50+
data[col] = pd.to_datetime(data[col], format=self._DATE_COLUMN_NAMES_BY_ENDPOINT[self.entity.name][col])
51+
elif col in data.columns:
52+
data[col] = pd.to_datetime(data[col])
5253
return data
5354

5455

bcb/odata/framework.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def __init__(self, obj, order):
155155
def __str__(self):
156156
return f"{self.obj.name} {self.order}"
157157

158+
def __repr__(self):
159+
return f"<{str(self)}>"
160+
158161

159162
class ODataPropertyFilter:
160163
def __init__(self, obj, oth, operator):
@@ -177,6 +180,9 @@ def statement(self):
177180
def __str__(self):
178181
return self.statement()
179182

183+
def __repr__(self):
184+
return f"<filter: {str(self)}>"
185+
180186

181187
class ODataProperty:
182188
def __init__(self, **kwargs):
@@ -216,7 +222,7 @@ def __eq__(self, other):
216222
return ODataPropertyFilter(self, other, "eq")
217223

218224
def __repr__(self):
219-
return f"<Property {self.name}>"
225+
return f"<Property {self.name}<{self.ftype}>>"
220226

221227

222228
class ODataFunction:
@@ -396,6 +402,7 @@ def __init__(self, entity, url):
396402
self._filter = []
397403
self._select = []
398404
self._orderby = []
405+
self._raw = False
399406
self.is_function = isinstance(entity, ODataFunctionImport)
400407
if self.is_function:
401408
self.function_parameters = {
@@ -450,8 +457,12 @@ def select(self, *args):
450457
self._select.extend(args)
451458
return self
452459

460+
def raw(self):
461+
self._raw = True
462+
return self
463+
453464
def _build_parameters(self):
454-
params = {"$format": "json"}
465+
params = {"$format": self._params.get("$format", "json")}
455466
if len(self._filter):
456467
_filter = " and ".join(str(f) for f in self._filter)
457468
params["$filter"] = _filter
@@ -470,6 +481,9 @@ def reset(self):
470481
self._params = {}
471482

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

486499
def show(self):
487500
print(f"URL:")

0 commit comments

Comments
 (0)