python列表get方法_Python json.get方法代码示例

庄瀚玥
2023-12-01

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

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

示例1: make_api_call_all_pages

​点赞 6

# 需要导入模块: 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,

示例2: make_api_call

​点赞 6

# 需要导入模块: 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,

示例3: list_object

​点赞 6

# 需要导入模块: 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,

示例4: scroll_object

​点赞 6

# 需要导入模块: 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,

示例5: get

​点赞 6

# 需要导入模块: 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,

示例6: login_page

​点赞 6

# 需要导入模块: 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,

示例7: vtables

​点赞 6

# 需要导入模块: 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,

示例8: classes

​点赞 6

# 需要导入模块: 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,

示例9: fromJsonFragment

​点赞 6

# 需要导入模块: 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,

示例10: fromJsonFragment

​点赞 6

# 需要导入模块: 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,

示例11: fromJsonFragment

​点赞 6

# 需要导入模块: 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,

示例12: get

​点赞 6

# 需要导入模块: 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,

示例13: authenticate

​点赞 6

# 需要导入模块: 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,

示例14: _get

​点赞 6

# 需要导入模块: 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,

示例15: team_events

​点赞 6

# 需要导入模块: 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,

示例16: team_matches

​点赞 6

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def team_matches(self, team, event=None, year=None, simple=False, keys=False):

"""

Get list of matches team has participated in.

:param team: Team to get matches of.

:param year: Year to get matches from.

:param event: Event to get matches from.

:param simple: Get only vital data.

:param keys: Only get match keys rather than their full data.

:return: List of string keys or Match objects.

"""

if event:

if keys:

return self._get('team/%s/event/%s/matches/keys' % (self.team_key(team), event))

else:

return [Match(raw) for raw in self._get('team/%s/event/%s/matches%s' % (self.team_key(team), event, '/simple' if simple else ''))]

elif year:

if keys:

return self._get('team/%s/matches/%s/keys' % (self.team_key(team), year))

else:

return [Match(raw) for raw in self._get('team/%s/matches/%s%s' % (self.team_key(team), year, '/simple' if simple else ''))]

开发者ID:frc1418,项目名称:tbapy,代码行数:23,

示例17: make_api_call

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def make_api_call(conf, action, params = {}, method = 'get', data = {}):

"""

Make an API call to Pipedrive.

The method can be 'get' or 'post'.

"""

parameters = {

'api_token': conf['API_KEY'],

'api_output': 'json'

}

parameters.update(params)

headers = {

'Content-type': 'application/json'

}

if method == 'get':

r = requests.request(method, conf['API_BASE_URL']+action, params=parameters)

elif method == 'post':

r = requests.request(method, conf['API_BASE_URL']+action, data=data, params=parameters)

else:

raise ValueError('Method should be get or post.')

print 'API call: ' + r.url

if ((r.status_code == 200 and method == 'get') or (r.status_code == 201 and method == 'post')) and r.json().get('success') == True:

return r.json()

else:

if 'error' in r.json():

raise IOError('API error ("%s") when calling: %s' % (r.json().get('error'), r.url) )

else:

raise IOError('API error (unknown) when calling: %s' % r.url )

开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:29,

示例18: _check_response

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def _check_response(response):

"""

Checks the HTTP response to see if it contains JSON. If it does, checks the JSON for error codes and messages.

Raises PardotAPIError if an error was found. If no error was found, returns the JSON. If JSON was not found,

returns the response status code.

"""

if response.headers.get('content-type') == 'application/json':

json = response.json()

error = json.get('err')

if error:

raise PardotAPIError(json_response=json)

return json

else:

return response.status_code

开发者ID:joshgeller,项目名称:PyPardot,代码行数:16,

示例19: authenticate

​点赞 5

# 需要导入模块: 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})

self.api_key = auth.get('api_key')

if self.api_key is not None:

return True

return False

except PardotAPIError:

return False

开发者ID:joshgeller,项目名称:PyPardot,代码行数:15,

示例20: __init__

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def __init__(self, username):

self.id=username

self.password_hash = rtkbaseconfig.get("general", "web_password_hash")

开发者ID:Stefal,项目名称:rtkbase,代码行数:5,

示例21: update_password

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def update_password(config_object):

"""

Check in settings.conf if web_password entry contains a value

If yes, this function will generate a new hash for it and

remove the web_password value

:param config_object: a RTKBaseConfigManager instance

"""

new_password = config_object.get("general", "new_web_password")

if new_password != "":

config_object.update_setting("general", "web_password_hash", generate_password_hash(new_password))

config_object.update_setting("general", "new_web_password", "")

开发者ID:Stefal,项目名称:rtkbase,代码行数:13,

示例22: check_update

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def check_update(source_url = None, current_release = None, prerelease=False, emit = True):

"""

Check if a RTKBase update exists

:param source_url: the url where we will try to find an update. It uses the github api.

:param current_release: The current RTKBase release

:param prerelease: True/False Get prerelease or not

:param emit: send the result to the web front end with socketio

:return The new release version inside a dict (release version and url for this release)

"""

new_release = {}

source_url = source_url if source_url is not None else "https://api.github.com/repos/stefal/rtkbase/releases"

current_release = current_release if current_release is not None else rtkbaseconfig.get("general", "version").strip("v")

current_release = current_release.replace("-beta", "").replace("-alpha", "").replace("-rc", "")

try:

response = requests.get(source_url)

response = response.json()

for release in response:

if release.get("prerelease") & prerelease or release.get("prerelease") == False:

latest_release = release.get("tag_name").strip("v").replace("-beta", "").replace("-alpha", "").replace("-rc", "")

if latest_release > current_release and latest_release <= rtkbaseconfig.get("general", "checkpoint_version"):

new_release = {"new_release" : release.get("tag_name"), "url" : release.get("assets")[0].get("browser_download_url"), "comment" : release.get("body")}

break

except Exception as e:

print("Check update error: ", e)

if emit:

socketio.emit("new release", json.dumps(new_release), namespace="/test")

print

return new_release

开发者ID:Stefal,项目名称:rtkbase,代码行数:33,

示例23: update_rtkbase

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def update_rtkbase():

"""

Check if a RTKBase exists, download it and update rtkbase

"""

#Check if an update is available

update_url = check_update(emit=False).get("url")

if update_url is None:

return

import tarfile

#Download update

update_archive = "/var/tmp/rtkbase_update.tar.gz"

try:

response = requests.get(update_url)

with open(update_archive, "wb") as f:

f.write(response.content)

except Exception as e:

print("Error: Can't download update - ", e)

#Get the "root" folder in the archive

tar = tarfile.open(update_archive)

for tarinfo in tar:

if tarinfo.isdir():

primary_folder = tarinfo.name

break

#Extract archive

tar.extractall("/var/tmp")

#launch update script

rtk.shutdownBase()

rtkbase_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))

source_path = os.path.join("/var/tmp/", primary_folder)

script_path = os.path.join(source_path, "rtkbase_update.sh")

current_release = rtkbaseconfig.get("general", "version").strip("v")

standard_user = rtkbaseconfig.get("general", "user")

os.execl(script_path, "unused arg0", source_path, rtkbase_path, app.config["DOWNLOAD_FOLDER"].split("/")[-1], current_release, standard_user)

开发者ID:Stefal,项目名称:rtkbase,代码行数:39,

示例24: inject_release

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def inject_release():

"""

Insert the RTKBase release number as a global variable for Flask/Jinja

"""

g.version = rtkbaseconfig.get("general", "version")

开发者ID:Stefal,项目名称:rtkbase,代码行数:7,

示例25: deleteLog

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def deleteLog(json):

rtk.logm.deleteLog(json.get("name"))

# Sending the the new available logs

getAvailableLogs()

#### Download and convert log handlers ####

开发者ID:Stefal,项目名称:rtkbase,代码行数:8,

示例26: processLog

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def processLog(json):

log_name = json.get("name")

print("Got signal to process a log, name = " + str(log_name))

print("Path to log == " + rtk.logm.log_path + "/" + str(log_name))

raw_log_path = rtk.logm.log_path + "/" + log_name

rtk.processLogPackage(raw_log_path)

开发者ID:Stefal,项目名称:rtkbase,代码行数:10,

示例27: cancelLogConversion

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def cancelLogConversion(json):

log_name = json.get("name")

raw_log_path = rtk.logm.log_path + "/" + log_name

rtk.cancelLogConversion(raw_log_path)

#### RINEX versioning ####

开发者ID:Stefal,项目名称:rtkbase,代码行数:8,

示例28: writeRINEXVersion

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def writeRINEXVersion(json):

rinex_version = json.get("version")

rtk.logm.setRINEXVersion(rinex_version)

#### Device hardware functions ####

开发者ID:Stefal,项目名称:rtkbase,代码行数:7,

示例29: __init__

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def __init__(self, session=None, json=None, auth=None):

self.session = session

self.id = json.get('id')

self.auth = auth

if self.session.lgn.ipython_enabled:

from ipykernel.comm import Comm

self.comm = Comm('lightning', {'id': self.id})

self.comm_handlers = {}

self.comm.on_msg(self._handle_comm_message)

开发者ID:lightning-viz,项目名称:lightning-python,代码行数:13,

示例30: get_html

​点赞 5

# 需要导入模块: import json [as 别名]

# 或者: from json import get [as 别名]

def get_html(self):

r = requests.get(self.get_embed_link(), auth=self.auth)

return r.text

开发者ID:lightning-viz,项目名称:lightning-python,代码行数:5,

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

 类似资料: