當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。