Python json.get() Examples

The following are 30 code examples of json.get(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module json , or try the search function .
Example #1
Source File: visualization.py    From lightning-python with MIT License 29 votes vote down vote up
def get_html(self):
        r = requests.get(self.get_embed_link(), auth=self.auth)
        return r.text 
Example #2
Source File: config_parser.py    From retdec-regression-tests-framework with MIT License 7 votes vote down vote up
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 
Example #3
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def send_verification_code(self, device):
        """ Requests that a verification code is sent to the given device"""
        data = json.dumps(device)
        request = self.session.post(
            '%s/sendVerificationCode' % self._setup_endpoint,
            params=self.params,
            data=data
        )
        verif_code = request.json().get('success', False)
        return verif_code


#------------------------------------------------------------------ 
Example #4
Source File: test.py    From MAX-Question-Answering with Apache License 2.0 5 votes vote down vote up
def test_metadata():

    model_endpoint = 'http://localhost:5000/model/metadata'

    r = requests.get(url=model_endpoint)
    assert r.status_code == 200

    metadata = r.json()
    assert metadata['id'] == 'max-question-answering'
    assert metadata['name'] == 'MAX Question Answering'
    assert metadata['description'] == 'Answer questions on a given corpus of text.'
    assert metadata['license'] == 'Apache 2.0'
    assert metadata['source'] == 'https://developer.ibm.com/exchanges/models/all/max-question-answering/' 
Example #5
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def contacts(self):
        return self.data.get('contactDetails') 
Example #6
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def my_fences(self):
        return self.data.get('myFencesISet') 
Example #7
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def friend_fences(self):
        return self.data.get('friendFencesISet') 
Example #8
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def details(self):
        return self.data.get('contactDetails')
#================================================================== 
Example #9
Source File: exceptions.py    From mlflow with Apache License 2.0 5 votes vote down vote up
def __init__(self, json):
        error_code = json.get('error_code', ErrorCode.Name(INTERNAL_ERROR))
        message = "%s: %s" % (error_code,
                              json['message'] if 'message' in json else "Response: " + str(json))
        super(RestException, self).__init__(message, error_code=ErrorCode.Value(error_code))
        self.json = json 
Example #10
Source File: main.py    From tbapy with MIT License 5 votes vote down vote up
def _detect_errors(self, json):
        if not isinstance(json, dict):
            return

        errors = json.get('Errors')
        if errors is not None:
            raise TBAErrorList([error.popitem() for error in errors]) 
Example #11
Source File: main.py    From tbapy with MIT License 5 votes vote down vote up
def teams(self, page=None, year=None, simple=False, keys=False):
        """
        Get list of teams.

        :param page: Page of teams to view. Each page contains 500 teams.
        :param year: View teams from a specific year.
        :param simple: Get only vital data.
        :param keys: Set to true if you only want the teams' keys rather than full data on them.
        :return: List of Team objects or string keys.
        """
        # If the user has requested a specific page, get that page.
        if page is not None:
            if year:
                if keys:
                    return self._get('teams/%s/%s/keys' % (year, page))
                else:
                    return [Team(raw) for raw in self._get('teams/%s/%s%s' % (year, page, '/simple' if simple else ''))]
            else:
                if keys:
                    return self._get('teams/%s/keys' % page)
                else:
                    return [Team(raw) for raw in self._get('teams/%s%s' % (page, '/simple' if simple else ''))]
        # If no page was specified, get all of them and combine.
        else:
            teams = []
            target = 0
            while True:
                page_teams = self.teams(page=target, year=year, simple=simple, keys=keys)
                if page_teams:
                    teams.extend(page_teams)
                else:
                    break
                target += 1
            return teams 
Example #12
Source File: main.py    From tbapy with MIT License 5 votes vote down vote up
def team(self, team, simple=False):
        """
        Get data on a single specified team.

        :param team: Team to get data for.
        :param simple: Get only vital data.
        :return: Team object with data on specified team.
        """
        return Team(self._get('team/%s%s' % (self.team_key(team), '/simple' if simple else ''))) 
Example #13
Source File: main.py    From tbapy with MIT License 5 votes vote down vote up
def team_years(self, team):
        """
        Get years during which a team participated in FRC.

        :param team: Key for team to get data about.
        :return: List of integer years in which team participated.
        """
        return self._get('team/%s/years_participated' % self.team_key(team)) 
Example #14
Source File: main.py    From tbapy with MIT License 5 votes vote down vote up
def team_media(self, team, year=None, tag=None):
        """
        Get media for a given team.

        :param team: Team to get media of.
        :param year: Year to get media from.
        :param tag: Get only media with a given tag.
        :return: List of Media objects.
        """
        return [Media(raw) for raw in self._get('team/%s/media%s%s' % (self.team_key(team), ('/tag/%s' % tag) if tag else '', ('/%s' % year) if year else ''))] 
Example #15
Source File: main.py    From tbapy with MIT License 5 votes vote down vote up
def team_districts(self, team):
        """
        Get districts a team has competed in.

        :param team: Team to get data on.
        :return: List of District objects.
        """
        return [District(raw) for raw in self._get('team/%s/districts' % self.team_key(team))] 
Example #16
Source File: exceptions.py    From mlflow with Apache License 2.0 5 votes vote down vote up
def get_http_status_code(self):
        return ERROR_CODE_TO_HTTP_STATUS.get(self.error_code, 500) 
Example #17
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def requestAppleWidgetKey(self, clientID):
        error_msg = ""
        self.session.headers.update(self.getRequestHeader())
        apple_widget_params = self.getQueryParameters(clientID)

        self.response = self.session.get(self.urlKey,
                                         params=apple_widget_params)

        try:
            response_json = self.response.json()
            if ('error' in response_json):
                error_msg = str(response_json.get('error'))

            if (error_msg != '' and
                    error_msg != "Missing X-APPLE-WEBAUTH-TOKEN cookie"):
                return False, error_msg

            self.appleWidgetKey = self.findQyery(self.response.text,
                                                 "widgetKey=")
        except Exception as e:
            if error_msg == '':
                error_msg = "Unknown Error"
            return False, error_msg
            #raise Exception(err_str,
            #                self.urlKey, repr(e))
        return True, self.appleWidgetKey

#------------------------------------------------------------------ 
Example #18
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def followers(self):
        return self.data.get('followers') 
Example #19
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def trusted_devices(self):
        """ Returns devices trusted for two-step authentication."""
        request = self.session.get(
            '%s/listDevices' % self._setup_endpoint,
            params=self.params
        )
        rtn_value = request.json().get('devices')
        return rtn_value


#------------------------------------------------------------------ 
Example #20
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def requires_2sa(self):
        """ Returns True if two-step authentication is required."""
        #return self.data.get('hsaChallengeRequired', False) \
        #    and self.data['dsInfo'].get('hsaVersion', 0) >= 1
        # FIXME: Implement 2FA for hsaVersion == 2
        rtn = self.data.get('hsaChallengeRequired', False) \
            and self.data['dsInfo'].get('hsaVersion', 0) >= 1

        return rtn

#------------------------------------------------------------------ 
Example #21
Source File: pyicloud_ic3.py    From obsolete-icloud3_v1.0.6 with MIT License 5 votes vote down vote up
def _get_cookiejar_path(self):
        # Get path for cookiejar file
        #return os.path.join(
        #    self._cookie_directory,
        #    ''.join([c for c in self.user.get('apple_id') if match(r'\w', c)])
        #)
        cookiejar_path = os.path.join(
            self._cookie_directory,
            ''.join([c for c in self.user.get('apple_id') if match(r'\w', c)])
        )

        return cookiejar_path


#------------------------------------------------------------------ 
Example #22
Source File: Functions.py    From codex-backend with MIT License 5 votes vote down vote up
def cursor_to_dict(f1, retrieve):
    results = []
    for f in f1:
        results.append(f)

    ret = []
    for a in results:
        dic = {}
        for key in retrieve.keys():
            steps = key.split('.')
            partial_res = a
            for step in steps:
                partial_res = partial_res.get(step)
                if partial_res is None:
                    break
                if isinstance(partial_res, list):
                    partial_res = None
                    break

            legend_to_show = key.split('.')[-1]
            if (legend_to_show == "file_id"):
                legend_to_show = "sha1"

            if (legend_to_show == "TimeDateStamp" and partial_res is not None):
                partial_res = time.strftime(
                    "%Y-%m-%d %H:%M:%S", time.gmtime(int(eval(partial_res), 16)))
            if (legend_to_show == "timeDateStamp" and partial_res is not None):
                partial_res = time.strftime(
                    "%Y-%m-%d %H:%M:%S", time.gmtime(partial_res))

            dic[legend_to_show] = partial_res

        ret.append(dic)
    return ret


# ****************TEST_CODE****************** 
Example #23
Source File: Functions.py    From codex-backend with MIT License 5 votes vote down vote up
def add_error(resp_dict, error_code, error_message):
    if type(resp_dict) != dict:
        return resp_dict
    if resp_dict.get('errors') is None:
        resp_dict["errors"] = []
    resp_dict["errors"].append({"code": error_code, "message": error_message})
    return resp_dict 
Example #24
Source File: Functions.py    From codex-backend with MIT License 5 votes vote down vote up
def change_date_to_str(res):
    if res is None:
        return None
    for date_key in ["date", "upload_date", "date_start", "date_end", "date_enqueued"]:
        if res.get(date_key) is None:
            pass
        else:
            res[date_key] = str(res.get(date_key))
    return res 
Example #25
Source File: Functions.py    From codex-backend with MIT License 5 votes vote down vote up
def key_list_clean(json):
    if json is None:
        return None
    array = []
    for key in json.keys():
        tmp_dict = {}
        tmp_dict["name"] = key
        tmp_dict["values"] = json.get(key)
        array.append(tmp_dict)
    return array 
Example #26
Source File: Functions.py    From codex-backend with MIT License 5 votes vote down vote up
def key_dict_clean(json):
    if json is None:
        return None
    array = []
    for key in json.keys():
        tmp_dict = json.get(key)
        tmp_dict["name"] = key
        array.append(tmp_dict)
    return array

# Replace dot with _
# in dictionaries keys
# in order to save them in mongo 
Example #27
Source File: Functions.py    From codex-backend with MIT License 5 votes vote down vote up
def get_eset_sig_from_scan(scans):
    if scans is None:
        return None
    for scan in scans:
        if scan.get('name') in ['ESET-NOD32', 'NOD32', 'NOD32v2']:
            return scan.get('result')
    return '' 
Example #28
Source File: server.py    From ReachView with GNU General Public License v3.0 5 votes vote down vote up
def resetConfig(json):
    rtk.resetConfigToDefault(json.get("name"))

#### Update ReachView #### 
Example #29
Source File: server.py    From ReachView with GNU General Public License v3.0 5 votes vote down vote up
def writeRINEXVersion(json):
    rinex_version = json.get("version")
    rtk.logm.setRINEXVersion(rinex_version)

#### Delete config #### 
Example #30
Source File: server.py    From ReachView with GNU General Public License v3.0 5 votes vote down vote up
def cancelLogConversion(json):
    log_name = json.get("name")
    raw_log_path = rtk.logm.log_path + "/" + log_name
    rtk.cancelLogConversion(raw_log_path)

#### RINEX versioning ####