Commit 9166e3f8 authored by Luciano Cauzzi's avatar Luciano Cauzzi

Fixed exists method

parent 6a103282
import json
from datetime import datetime
from datetime import datetime, timezone
from logger_library import Logger
......@@ -94,7 +94,12 @@ class AppPyramidManager:
return self.exists(query_header, query_id)
json_obj = json.loads(response.text)
attachments = json_obj["hits"]["hits"]
return AppPyramidManager.__manage_response__(response.status_code, operation_name, json_obj["hits"]["hits"][0]["_id"] if len(attachments) > 0 else None)
if response.status_code != 200:
return NetworkResult(success=False, status_code=response.status_code, message="", result=None)
if len(attachments) > 0:
return NetworkResult(success=True, status_code=response.status_code, message="", result=True)
else:
return NetworkResult(success=True, status_code=response.status_code, message="", result=False)
except Exception as e:
return AppPyramidManager.__generate_generic_error__(operation_name, e)
......@@ -128,9 +133,8 @@ class AppPyramidManager:
self.login()
def __is_token_expired__(self) -> bool:
return self.__app_token__.expire < AppPyramidManager.__unix_time_millis__(datetime.now())
return self.__app_token__.expire < AppPyramidManager.__unix_time_millis__()
@staticmethod
def __unix_time_millis__(dt):
epoch = datetime.utcfromtimestamp(0)
return (dt - epoch).total_seconds() * 1000.0
def __unix_time_millis__():
return datetime.now(timezone.utc).microsecond * 1000
......@@ -3,7 +3,7 @@ import setuptools
setup(
name='network_manager',
version='0.1.6',
version='0.1.7',
packages=setuptools.find_packages(),
dependency_links=['http://github.comune.brescia.it/innovation-that-excites/logger_library#egg=logger_library'],
install_requires=['logger_library', 'dependency_injector', 'requests'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment