当前位置: 首页>>代码示例>>Python>>正文


Python json.get方法代码示例

本文整理汇总了Python中json.get方法的典型用法代码示例。如果您正苦于以下问题:Python json.get方法的具体用法?Python json.get怎么用?Python json.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在json的用法示例。


在下文中一共展示了json.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_api_call_all_pages

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def make_api_call_all_pages(conf, action, params = {}):
    """
    A wrapper of make_api_call() to get all pages on a GET request
    """
    start = 0
    results = []
    looping = True
    params.update({'limit':conf['PAGINATION']})
    while looping:
        params.update({'start':start})
        json = make_api_call(conf, action, params)
        for r in json.get('data'):
            results.append(r)
        is_more = json.get('additional_data').get('pagination').get('more_items_in_collection')
        if is_more:
            start = json.get('additional_data').get('pagination').get('next_start')
        else:
            looping = False
    return results 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,代码来源:pipedriveapi.py

示例2: make_api_call

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def make_api_call(action, token, parameters = {}, method = 'get', data = {}):
    """
    Makes an API call to Intercom
    """
    headers = {
        'Content-type': 'application/json',
        'Accept': 'application/json',
        'Accept-Encoding': 'gzip',
        'Authorization': 'Bearer %s' % token
    }
    if method == 'get':
        r = s.request(method, 'https://api.intercom.io/'+action, headers=headers, params=parameters, timeout=30)
    else:
        raise ValueError('Unimplemented method.')
    logging.info('Intercom plugin - API %s call: %s' % (method, r.url) )
    if r.status_code < 300:
        return r.json()
    else:
        raise Exception('API error when calling %s (code %i): %s' % (r.url, r.status_code, r.content)) 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,代码来源:intercomapi.py

示例3: list_object

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def list_object(object_name, token, parameters = {}):
    """
    A generator that wraps make_api_call() to get all items of an object
    """
    looping = True
    parameters.update({'page': None})
    while looping:
        json = make_api_call(object_name, token, parameters)
        logging.info('Intercom plugin - %s: results = %i' % (object_name, len(json.get(object_name))) )
        for r in json.get(object_name):
            yield r
        next = json.get('pages', {}).get('next')
        logging.info('Intercom plugin - %s: next = %s' % (object_name, next) )
        if next is None:
            looping = False
        else:
            # next contains an url, let's extract the url params
            new_params = dict(urlparse.parse_qs(urlparse.urlparse(next).query))
            parameters.update(new_params) 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,代码来源:intercomapi.py

示例4: scroll_object

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def scroll_object(object_name, token, parameters = {}):
    """
    A generator that wraps make_api_call() to get all items of an object using the scpecial scroll endpoint
    """
    page = None
    looping = True
    while looping:
        parameters.update({'scroll_param':page})
        json = make_api_call(object_name+'/scroll', token, parameters)
        logging.info('Intercom plugin - %s: scroll_param = %s' % (object_name, json.get("scroll_param")) )
        logging.info('Intercom plugin - %s: results = %i' % (object_name, len(json.get(object_name))) )
        for r in json.get(object_name):
            yield r
        page = json.get('scroll_param')
        if page is None or len(json.get(object_name)) == 0:
            looping = False 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:18,代码来源:intercomapi.py

示例5: get

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def get(self, object_name, path=None, params=None, retries=0):
        """
        Makes a GET request to the API. Checks for invalid requests that raise PardotAPIErrors. If the API key is
        invalid, one re-authentication request is made, in case the key has simply expired. If no errors are raised,
        returns either the JSON response, or if no JSON was returned, returns the HTTP response status code.
        """
        if params is None:
            params = {}
        params.update({'user_key': self.user_key, 'api_key': self.api_key, 'format': 'json'})
        try:
            self._check_auth(object_name=object_name)
            request = requests.get(self._full_path(object_name, path), params=params)
            response = self._check_response(request)
            return response
        except PardotAPIError as err:
            if err.message == 'Invalid API key or user key':
                response = self._handle_expired_api_key(err, retries, 'get', object_name, path, params)
                return response
            else:
                raise err 
开发者ID:joshgeller,项目名称:PyPardot,代码行数:22,代码来源:client.py

示例6: login_page

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def login_page():
    if current_user.is_authenticated:
        return redirect(url_for('status_page'))
    loginform = LoginForm()
    if loginform.validate_on_submit():
        user = User('admin')
        password = loginform.password.data
        if not user.check_password(password):
            return abort(401)
        
        login_user(user, remember=loginform.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('status_page')

        return redirect(next_page)
        
    return render_template('login.html', title='Sign In', form=loginform) 
开发者ID:Stefal,项目名称:rtkbase,代码行数:20,代码来源:server.py

示例7: vtables

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def vtables(self):
        """Virtual tables (list of :class:`Vtable`).

        The returned list can be indexed by either positions (0, 1, ...) or
        vtable names. Example:

        .. code-block:: python

            module.vtables[0]       # Returns the first vtable.
            module.vtables['vt1']   # Returns the vtable named 'vt1'.

        """
        vtables = NamedObjectList()
        for vt in self.json.get('vtables', []):
            vtables.append(Vtable(vt))
        return vtables 
开发者ID:avast,项目名称:retdec-regression-tests-framework,代码行数:18,代码来源:config_parser.py

示例8: classes

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def classes(self):
        """C++ classes (list of :class:`Class`).

        The returned list can be indexed by either positions (0, 1, ...) or
        classes' names. Example:

        .. code-block:: python

            module.classes[0]        # Returns the first class.
            module.classes['class1'] # Returns the class named 'class1'.

        """
        classes = NamedObjectList()
        for c in self.json.get('classes', []):
            classes.append(Class(c))
        return classes 
开发者ID:avast,项目名称:retdec-regression-tests-framework,代码行数:18,代码来源:config_parser.py

示例9: fromJsonFragment

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def fromJsonFragment(json, nameFromParent):
        if isinstance(json, dict) and hasKeys(json.keys(), ["entries", "sum"], ["name"]):
            if json["entries"] in ("nan", "inf", "-inf") or isinstance(json["entries"], numbers.Real):
                entries = float(json["entries"])
            else:
                raise JsonFormatException(json["entries"], "Sum.entries")

            if isinstance(json.get("name", None), basestring):
                name = json["name"]
            elif json.get("name", None) is None:
                name = None
            else:
                raise JsonFormatException(json["name"], "Sum.name")

            if json["sum"] in ("nan", "inf", "-inf") or isinstance(json["sum"], numbers.Real):
                sum = float(json["sum"])
            else:
                raise JsonFormatException(json["sum"], "Sum.sum")

            out = Sum.ed(entries, sum)
            out.quantity.name = nameFromParent if name is None else name
            return out.specialize()

        else:
            raise JsonFormatException(json, "Sum") 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:27,代码来源:sum.py

示例10: fromJsonFragment

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def fromJsonFragment(json, nameFromParent):
        if isinstance(json, dict) and hasKeys(json.keys(), ["entries", "min"], ["name"]):
            if json["entries"] in ("nan", "inf", "-inf") or isinstance(json["entries"], numbers.Real):
                entries = float(json["entries"])
            else:
                raise JsonFormatException(json["entries"], "Minimize.entries")

            if isinstance(json.get("name", None), basestring):
                name = json["name"]
            elif json.get("name", None) is None:
                name = None
            else:
                raise JsonFormatException(json["name"], "Minimize.name")

            if json["min"] in ("nan", "inf", "-inf") or isinstance(json["min"], numbers.Real):
                min = float(json["min"])
            else:
                raise JsonFormatException(json["min"], "Minimize.min")

            out = Minimize.ed(entries, min)
            out.quantity.name = nameFromParent if name is None else name
            return out.specialize()

        else:
            raise JsonFormatException(json, "Minimize") 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:27,代码来源:minmax.py

示例11: fromJsonFragment

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def fromJsonFragment(json, nameFromParent):
        if isinstance(json, dict) and hasKeys(json.keys(), ["entries", "mean"], ["name"]):
            if json["entries"] in ("nan", "inf", "-inf") or isinstance(json["entries"], numbers.Real):
                entries = float(json["entries"])
            else:
                raise JsonFormatException(json["entries"], "Average.entries")

            if isinstance(json.get("name", None), basestring):
                name = json["name"]
            elif json.get("name", None) is None:
                name = None
            else:
                raise JsonFormatException(json["name"], "Average.name")

            if json["mean"] in ("nan", "inf", "-inf") or isinstance(json["mean"], numbers.Real):
                mean = float(json["mean"])
            else:
                raise JsonFormatException(json["mean"], "Average.mean")

            out = Average.ed(entries, mean)
            out.quantity.name = nameFromParent if name is None else name
            return out.specialize()

        else:
            raise JsonFormatException(json, "Average") 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:27,代码来源:average.py

示例12: get

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def get(self, object_name, path=None, params=None, retries=0):
        """
        Makes a GET request to the API. Checks for invalid requests that raise PardotAPIErrors. If the API key is
        invalid, one re-authentication request is made, in case the key has simply expired. If no errors are raised,
        returns either the JSON response, or if no JSON was returned, returns the HTTP response status code.
        """
        if params is None:
            params = {}
        params.update({'format': 'json'})
        headers = self._build_auth_header()
        try:
            self._check_auth(object_name=object_name)
            request = requests.get(self._full_path(object_name, self.version, path), params=params, headers=headers)
            response = self._check_response(request)
            return response
        except PardotAPIError as err:
            if err.message == 'Invalid API key or user key':
                response = self._handle_expired_api_key(err, retries, 'get', object_name, path, params)
                return response
            else:
                raise err 
开发者ID:mneedham91,项目名称:PyPardot4,代码行数:23,代码来源:client.py

示例13: authenticate

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def authenticate(self):
        """
         Authenticates the user and sets the API key if successful. Returns True if authentication is successful,
         False if authentication fails.
        """
        try:
            auth = self.post('login', params={'email': self.email, 'password': self.password})
            if type(auth) is int:
                # sometimes the self.post method will return a status code instead of JSON response on failures
                return False
            self.api_key = auth.get('api_key', None)
            if self.api_key is not None:
                return True
            return False
        except PardotAPIError:
            return False 
开发者ID:mneedham91,项目名称:PyPardot4,代码行数:18,代码来源:client.py

示例14: _get

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def _get(self, url):
        """
        Helper method: GET data from given URL on TBA's API.

        :param url: URL string to get data from.
        :return: Requested data in JSON format.
        """
        extra_headers = {}
        if self._if_modified_since is not None:
            extra_headers['If-Modified-Since'] = self._if_modified_since

        response = self.session.get(self.READ_URL_PRE + url, headers=extra_headers)
        last_modified = response.headers.get('Last-Modified')
        
        if last_modified is not None:
            if response.status_code == 304:
                raise NotModifiedException(response.headers['Last-Modified'])

            if self._last_modified:
                self._last_modified = LastModifiedDate(last_modified)

        raw = response.json()
        self._detect_errors(raw)
        return raw 
开发者ID:frc1418,项目名称:tbapy,代码行数:26,代码来源:main.py

示例15: team_events

# 需要导入模块: import json [as 别名]
# 或者: from json import get [as 别名]
def team_events(self, team, year=None, simple=False, keys=False):
        """
        Get team events a team has participated in.

        :param team: Team to get events for.
        :param year: Year to get events from.
        :param simple: Get only vital data.
        :param keys: Get just the keys of the events. Set to True if you only need the keys of each event and not their full data.
        :return: List of strings or Teams
        """
        if year:
            if keys:
                return self._get('team/%s/events/%s/keys' % (self.team_key(team), year))
            else:
                return [Event(raw) for raw in self._get('team/%s/events/%s%s' % (self.team_key(team), year, '/simple' if simple else ''))]
        else:
            if keys:
                return self._get('team/%s/events/keys' % self.team_key(team))
            else:
                return [Event(raw) for raw in self._get('team/%s/events%s' % (self.team_key(team), '/simple' if simple else ''))] 
开发者ID:frc1418,项目名称:tbapy,代码行数:22,代码来源:main.py


注:本文中的json.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。