brynq-sdk-zermelo 1.0.1__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_zermelo
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Zermelo wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -332,7 +332,7 @@ class Zermelo(BrynQ):
332
332
  df.index.name = 'appointments_{0}_id'.format(col_name)
333
333
  df.to_csv(file, sep='|', decimal=',')
334
334
 
335
- def get_zermelo_filtered(self, endpoint: str, fields: List = None, startdate = None, enddate = None, filters: dict = None) -> pd.DataFrame:
335
+ def get_zermelo_filtered(self, endpoint: str, fields: List = None, startdate=None, enddate=None, filters: dict = None) -> pd.DataFrame:
336
336
  """
337
337
  :param endpoint: endpoint
338
338
  :param fields: fields to get, if left empty, all fields are returned
@@ -341,7 +341,7 @@ class Zermelo(BrynQ):
341
341
  :param filters: dict of fields with corresponding values to filter
342
342
  :return:
343
343
  """
344
- # Loop through the data per 3 days (3600 seconds * 24 hours * 3 days) because the dataset is too big to receive in once. Start three years back
344
+ # Loop through the data per 7 days (3600 seconds * 24 hours * 7 days) because the dataset is too big to receive at once.
345
345
  df = pd.DataFrame()
346
346
  url = f'{self.url}{endpoint}'
347
347
  params = {'access_token': self.access_token}
@@ -354,33 +354,55 @@ class Zermelo(BrynQ):
354
354
  if startdate is not None:
355
355
  start_epoch = int(time.mktime(startdate))
356
356
  last_epoch = int(time.mktime(enddate))
357
- # loop epoch is 3 days from start_date except when last_epoch is smaller than start + 3days
357
+ # loop epoch is 7 days from start_date except when last_epoch is smaller than start + 7 days
358
358
  end_epoch = int(start_epoch + (3600 * 24 * 7)) if (start_epoch + (3600 * 24 * 7)) < last_epoch else last_epoch
359
+
359
360
  while start_epoch < last_epoch:
360
361
  try:
361
362
  # merge params with loop params
362
363
  time_params = params | {'start': start_epoch, 'end': end_epoch}
363
- resp = requests.get(url=url,
364
- params=time_params
365
- )
364
+ resp = requests.get(url=url, params=time_params)
366
365
  resp.raise_for_status()
366
+
367
367
  data = resp.json()['response']['data']
368
368
 
369
369
  # checks if data is not empty list
370
370
  if len(data) > 0:
371
371
  df = pd.concat([df, pd.DataFrame(data)])
372
372
 
373
+ # move to next 7-day block
373
374
  start_epoch += (3600 * 24 * 7)
374
375
  end_epoch += (3600 * 24 * 7)
376
+ # Adjust end_epoch to not exceed last_epoch
377
+ if end_epoch > last_epoch:
378
+ end_epoch = last_epoch
379
+
380
+ except requests.exceptions.HTTPError as http_err:
381
+ # Stop the loop for certain HTTP errors like 403 or 401
382
+ if resp.status_code == 403:
383
+ print('{} - 403 Forbidden at timestamp {}: {}'.format(time.strftime('%H:%M:%S'), start_epoch, http_err))
384
+ break # Stop the loop for 403 error
385
+ elif resp.status_code == 401:
386
+ print('{} - 401 Unauthorized at timestamp {}: {}'.format(time.strftime('%H:%M:%S'), start_epoch, http_err))
387
+ break # Stop the loop for 401 error
388
+
389
+ # For other HTTP errors, retry the loop
390
+ print('{} - HTTP Error at timestamp {}: {}'.format(time.strftime('%H:%M:%S'), start_epoch, http_err))
391
+ start_epoch += (3600 * 24 * 7) # Move forward to next block to prevent endless retry
375
392
 
376
393
  except Exception as e:
377
- print('{} - Error at timestamp {}: {}'.format(time.strftime('%H:%M:%S'), start_epoch, e))
378
- # retries
379
- continue
394
+ # Handle other types of exceptions (e.g., network errors)
395
+ print('{} - General Error at timestamp {}: {}'.format(time.strftime('%H:%M:%S'), start_epoch, e))
396
+ start_epoch += (3600 * 24 * 7) # Skip this block to avoid infinite retry
380
397
  else:
381
- resp = requests.get(url=url, params=params)
382
- resp.raise_for_status()
383
- data = resp.json()['response']['data']
384
- df = pd.DataFrame(data)
398
+ try:
399
+ resp = requests.get(url=url, params=params)
400
+ resp.raise_for_status()
401
+ data = resp.json()['response']['data']
402
+ df = pd.DataFrame(data)
403
+ except requests.exceptions.HTTPError as http_err:
404
+ print('{} - HTTP Error: {}'.format(time.strftime('%H:%M:%S'), http_err))
405
+ except Exception as e:
406
+ print('{} - General Error: {}'.format(time.strftime('%H:%M:%S'), e))
385
407
 
386
408
  return df
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-zermelo
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Zermelo wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name='brynq_sdk_zermelo',
6
- version='1.0.1',
6
+ version='1.0.2',
7
7
  description='Zermelo wrapper from BrynQ',
8
8
  long_description='Zermelo wrapper from BrynQ',
9
9
  author='BrynQ',