Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion empowering/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
try:
VERSION = __import__('pkg_resources') \
.get_distribution(__name__).version
except Exception, e:
except Exception as e:
VERSION = 'unknown'

from service import Empowering
Expand Down
4 changes: 2 additions & 2 deletions empowering/executors/urllib2_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

logger = logging.getLogger('empowering.executors.urllib2_executor')

API_HOST = 'api.empowering.cimne.com'
DEBUG_API_HOST = '91.121.140.152'
API_HOST = 'api.beedataanalytics.com'
DEBUG_API_HOST = 'devapi.beedataanalytics.com'


class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
Expand Down
7 changes: 5 additions & 2 deletions empowering/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ def delete(self, etag):
return request, parsers.parse_json

@base.apimethod
def get(self, where=None, sort=None):
def get(self, where=None, sort=None, rid=None):
sort = sort and sort.replace(' ', '')
params = base.get_params(('where', 'sort'), locals())
request = http.Request('GET', self.get_url(), params)
url = self.get_url()
if rid:
url = '{}/{}'.format(url, rid)
request = http.Request('GET', url, params)

return request, parsers.parse_json

Expand Down
51 changes: 47 additions & 4 deletions empowering/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
class Contracts(EmpoweringResource):
path = 'contracts'

def wrap_object(self, obj):
serializer = models.Contract()
return serializer.dump(obj).data


class AmonMeasures(EmpoweringResource):
path = 'amon_measures'
Expand All @@ -47,6 +43,14 @@ def delete(self, obj, etag):
raise base.MethodNotSupported


class ResidentialTimeofuseAmonMeasures(AmonMeasures):
path = 'residential_timeofuse_amon_measures'


class TertiaryAmonMeasures(AmonMeasures):
path = 'tertiary_amon_measures'


class AmonMeasuresMeasurements(EmpoweringResource):
path = 'amon_measures_measurements'

Expand All @@ -72,6 +76,22 @@ def __init__(self, *args, **kwargs):
DeprecationWarning)


class Tariffs(EmpoweringResource):
path = 'raw_tariffs'


class PriceIndexed(EmpoweringResource):
path = 'price_indexed'

@base.apimethod
def update(self, obj, _id):
raise base.MethodNotSupported

@base.apimethod
def delete(self, obj, _id):
raise base.MethodNotSupported


class Empowering(base.Resource):
"""
Empowering Insight Engine Service API.
Expand Down Expand Up @@ -123,6 +143,13 @@ def add_cookie_token(self, request):
def get_url(self):
return "{0}/{1}".format(self.apiroot, self.version)

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
if self.login_handler and self.token:
self.logout()

def login(self, user, password):
if self.login_handler and self.token:
return {'success': True, 'token': self.token}
Expand Down Expand Up @@ -152,6 +179,14 @@ def logout(self):
def amon_measures(self):
return AmonMeasures(self)

@base.resource(ResidentialTimeofuseAmonMeasures)
def residential_timeofuse_amon_measures(self):
return ResidentialTimeofuseAmonMeasures(self)

@base.resource(TertiaryAmonMeasures)
def tertiary_amon_measures(self):
return TertiaryAmonMeasures(self)

@base.resource(Measures)
def measures(self):
warn('Deprecated. Use amon_measures_measurements', DeprecationWarning)
Expand All @@ -169,6 +204,14 @@ def contract(self, contract_id):
def contracts(self):
return Contracts(self)

@base.resource(Tariffs)
def tariffs(self):
return Tariffs(self)

@base.resource(PriceIndexed)
def price_indexed(self):
return PriceIndexed(self)

@base.resource(OT101Results)
def ot101_result(self, result_id):
return OT101Results(self, result_id)
Expand Down
8 changes: 6 additions & 2 deletions empowering/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import times
import ssl
from arrow.parser import DateTimeParser
import os


# Monkey patch parse function for times library (newer)
Expand Down Expand Up @@ -89,8 +90,11 @@ def make_uuid(model, model_id):
model = model.encode('utf-8')
if isinstance(model_id, unicode):
model_id = model_id.encode('utf-8')
token = '%s,%s' % (model, model_id)
return str(uuid.uuid5(uuid.NAMESPACE_OID, token))
if int(os.getenv('ANONIMIZE', '1')):
token = '%s,%s' % (model, model_id)
return str(uuid.uuid5(uuid.NAMESPACE_OID, token))
else:
return str(model_id)


def make_utc_timestamp(timestamp, timezone='Europe/Madrid'):
Expand Down