Exemple #1
0
 def method(*args, **kargs):
     url = self.__url + "/" + name
     # Put positional arguments into keyword arguments as we want all the
     # parameters to go through POST
     if args:
         kargs["__dwsargs__"] = args
     for key in kargs.keys():
         kargs[key] = to_json(kargs[key])
     result = callservice(url, headers__=self.__headers, **kargs)
     result = from_json(result)
     return result
Exemple #2
0
    def get_current_user(self):
        user_json = self.get_secure_cookie(USER_COOKIE_NAME)
        if user_json:
            user_dict = helper.from_json(user_json)
            user = CookieUser(**user_dict)
            if user and user._id:
                return user

        return None

        """This is the Facbook login logic
Exemple #3
0
from helper import OuraModel, from_json


class Readiness(OuraModel):
    _KEYS = [
        "summary_date", "period_id", "score", "score_previous_night",
        "score_sleep_balance", "score_previous_day", "score_activity_balance",
        "score_resting_hr", "score_recovery_index", "score_temperature"
    ]


if __name__ == '__main__':
    test = """
{
        "summary_date": "2016-09-03",
        "period_id": 0,
        "score": 62,
        "score_previous_night": 5,
        "score_sleep_balance": 75,
        "score_previous_day": 61,
        "score_activity_balance": 77,
        "score_resting_hr": 98,
        "score_recovery_index": 45,
        "score_temperature": 86
}"""

    readiness = from_json(test, Readiness)
    print(readiness)
Exemple #4
0
        "timezone": 180,
        "score": 87,
        "score_stay_active": 90,
        "score_move_every_hour": 100,
        "score_meet_daily_targets": 60,
        "score_training_frequency": 96,
        "score_training_volume": 95,
        "score_recovery_time": 100,
        "daily_movement": 7806,
        "non_wear": 313,
        "rest": 426,
        "inactive": 429,
        "inactivity_alerts": 0,
        "low": 224,
        "medium": 49,
        "high": 0,
        "steps": 9206,
        "cal_total": 2540,
        "cal_active": 416,
        "met_min_inactive": 9,
        "met_min_low": 167,
        "met_min_medium_plus": 159,
        "met_min_medium": 159,
        "met_min_high": 0,
        "average_met": 1.4375,
        "class_5min":"1112211111111111111111111111111111111111111111233322322223333323322222220000000000000000000000000000000000000000000000000000000233334444332222222222222322333444432222222221230003233332232222333332333333330002222222233233233222212222222223121121111222111111122212321223211111111111111111",
        "met_1min": [ 1.2,1.1,0.9,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2,0.9,1.1,0.9,0.9,0.9,1.1,0.9,0.9,1.1,1.2,1.6,0.9,1.1,1.4,3.7,2.8,3.2,2.7,1.2,1.2,1.3,1.3,1.3,1.2,1.2,0.9,0.9,0.9,1.1,1.1,0.9,1.1,1.3,0.9,1.1,1.1,1.1,1.3,4.1,1.5,1.7,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.1,0.9,0.9,0.9,1.1,1.3,0.9,0.9,0.9,0.9,0.9,0.9,1.1,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,1.1,0.9,0.9,0.9,0.9,1.1,0.9,0.9,1.1,0.9,0.9,0.9,0.9,0.9,1.1,0.9,0.9,0.9,0.9,0.9,0.9,0.9,1.1,0.9,1.3,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9,0.9 ]
    }"""

    activity = from_json(test, Activity)
    print(activity)
Exemple #5
0
        except AttributeError:
            raise AttributeError("The ESB is not set")

        try:
            methods = callservice(url, headers__=self.__headers)
        except HTTPError, e:
            if e.code == 401:
                # Unauthorized
                if self.__key:
                    raise ValueError("The key %s does not grant access to %s" % (self.__key, self.get_esb()))
                raise ValueError("The access to server %s is unauthorized" % self.get_esb())
            raise ValueError("The service %s was not found in %s" % (name__, self.get_esb()))
        except URLError:
            raise ValueError("The ESB was not found in %s" % (self.get_esb()))

        for method in from_json(methods):
            setattr(self, method, self.__hide(method))

    @property
    def __url(self):
        return self.get_esb() + "/" + self.__name

    def __hide(self, name):
        def method(*args, **kargs):
            url = self.__url + "/" + name
            # Put positional arguments into keyword arguments as we want all the
            # parameters to go through POST
            if args:
                kargs["__dwsargs__"] = args
            for key in kargs.keys():
                kargs[key] = to_json(kargs[key])
Exemple #6
0
    def __call__(self, environ, start_response):
        base_url = self.config['controller']
        req_url = environ.get('PATH_INFO')
        if not req_url.startswith(base_url + '/') and req_url != base_url:
            return self.not_found(start_response)

        proc_start = time.time()

        try:
            assert self.access_key == environ.get('HTTP_AUTHORIZATION')
            log.debug('Access granted with key %s' % \
                environ.get('HTTP_AUTHORIZATION'))
        except:
            log.warn('Access unauthorized. Environment:\n%s' % environ)
            return self.auth_required(start_response)

        environ['SCRIPT_NAME'] = base_url
        environ['PATH_INFO'] = environ['PATH_INFO'].split(base_url)[1]

        servicename = path_info_pop(environ)
        # Describe myself
        if not servicename:
            desc = self.describe(start_response)
            log.info('Describing esb')
            log.debug('Returning %s' % desc[0])
            return desc

        try:
            service = self.services[servicename]['service']
        except:
            # There is no such service
            log.warn('Service %s not found or not working' % servicename)
            return self.not_found(start_response)
        
        methodname = path_info_pop(environ)
        if not methodname:
            # The request about the service itself
            desc = self.describe_service(servicename, start_response)
            log.info('Describing %s' % servicename)
            log.debug('Returning %s' % desc[0])
            return desc

        # A method was called
        try:
            method = getattr(service, methodname)
            assert getattr(method, 'webmethod', False)
        except:
            # The service does not have such a webmethod
            log.warn('A webmethod %s.%s not found' % (servicename, methodname))
            return self.not_found(start_response)

        kargs = dict()
        try:
            kargs = dict(parse_formvars(environ, include_get_vars=True))
            for karg in kargs.keys():
                kargs[karg] = from_json(kargs[karg])
        except:
            log.warn('Failed to parse parameters for %s.%s: %s' % (servicename,
                methodname, kargs))
            return self.request_error(start_response, 'Invalid parameters')

        # Extract the positional arguments:
        args = kargs.pop('__dwsargs__', [])

        # Call the method
        if is_testing():
            result = method(*args, **kargs)
            result = to_json(result)
        else:
            try:
                exec_start = time.time()
                result = method(*args, **kargs)
                exec_time = (time.time() - exec_start) * 1000

                log.info('%s.%s finished in %.2f ms' % (servicename,
                    methodname, exec_time))
                log.debug('\nArgs: %s\nKargs: %s\nResult: %s' % (args, kargs,
                    result))

                result = to_json(result)
                elixir.session.close()
            except Exception, e:
                exc = format_exc(e)
                start_response('500 Internal Server Error',
                    [('Content-Type', 'text/html')])

                log.error('%s.%s\n%s' % (servicename, methodname, exc))
                elixir.session.close()
                return ['Internal server error']
Exemple #7
0
import json
from helper import OuraModel, from_json

class UserInfo(OuraModel):
    _KEYS = ['age', 'weight', 'gender', 'email']


if __name__ == '__main__':

    test = """
{
    "age": 27,
    "weight": 80,
    "email": "*****@*****.**",
    "surprise" : "wow this is new"
}"""

    u = from_json(test, UserInfo)
    print(u)
    
Exemple #8
0
  "bedtime_end": "2017-11-06T08:12:19+02:00",
  "score": 70,
  "score_total": 57,
  "score_disturbances": 83,
  "score_efficiency": 99,
  "score_latency": 88,
  "score_rem": 97,
   "score_deep": 59,
  "score_alignment": 31,
  "total": 20310,
  "duration": 21540,
  "awake": 1230,
  "light": 10260,
  "rem": 7140,
  "deep": 2910,
  "onset_latency": 480,
  "restless": 39,
  "efficiency": 94,
  "midpoint_time": 11010,
  "hr_lowest": 49,
  "hr_average": 56.375,
  "rmssd": 54,
  "breath_average": 13,
  "temperature_delta": -0.06,
  "hypnogram_5min": "443432222211222333321112222222222111133333322221112233333333332232222334",
  "hr_5min": [0, 53, 51, 0, 50, 50, 49, 49, 50, 50, 51, 52, 52, 51, 53, 58, 60, 60, 59, 58, 58, 58, 58, 55, 55, 55, 55, 56, 56, 55, 53, 53, 53, 53, 53, 53, 57, 58, 60, 60, 59, 57, 59, 58, 56, 56, 56, 56, 55, 55, 56, 56, 57, 58, 55, 56, 57, 60, 58, 58, 59, 57, 54, 54, 53, 52, 52, 55, 53, 54, 56, 0],
  "rmssd_5min": [0, 0, 62, 0, 75, 52, 56, 56, 64, 57, 55, 78, 77, 83, 70, 35, 21, 25, 49, 44, 48, 48, 62, 69, 66, 64, 79, 59, 67, 66, 70, 63, 53, 57, 53, 57, 38, 26, 18, 24, 30, 35, 36, 46, 53, 59, 50, 50, 53, 53, 57, 52, 41, 37, 49, 47, 48, 35, 32, 34, 52, 57, 62, 57, 70, 81, 81, 65, 69, 72, 64, 0]
}"""

    sleep = from_json(test, Sleep)
    print(sleep)