本文整理汇总了Python中web.get方法的典型用法代码示例。如果您正苦于以下问题:Python web.get方法的具体用法?Python web.get怎么用?Python web.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类web
的用法示例。
在下文中一共展示了web.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_workflow
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def download_workflow(url):
"""Download workflow at ``url`` to a local temporary file.
:param url: URL to .alfredworkflow file in GitHub repo
:returns: path to downloaded file
"""
filename = url.split('/')[-1]
if (not filename.endswith('.alfredworkflow') and
not filename.endswith('.alfred3workflow')):
raise ValueError('attachment not a workflow: {0}'.format(filename))
local_path = os.path.join(tempfile.gettempdir(), filename)
wf().logger.debug(
'downloading updated workflow from `%s` to `%s` ...', url, local_path)
response = web.get(url)
with open(local_path, 'wb') as output:
output.write(response.content)
return local_path
示例2: install_update
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def install_update():
"""If a newer release is available, download and install it.
:returns: ``True`` if an update is installed, else ``False``
"""
update_data = wf().cached_data('__workflow_update_status', max_age=0)
if not update_data or not update_data.get('available'):
wf().logger.info('no update available')
return False
local_file = download_workflow(update_data['download_url'])
wf().logger.info('installing updated workflow ...')
subprocess.call(['open', local_file])
update_data['available'] = False
wf().cache_data('__workflow_update_status', update_data)
return True
示例3: retrieve_download
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def retrieve_download(dl):
"""Saves a download to a temporary file and returns path.
.. versionadded: 1.37
Args:
url (unicode): URL to .alfredworkflow file in GitHub repo
Returns:
unicode: path to downloaded file
"""
if not match_workflow(dl.filename):
raise ValueError('attachment not a workflow: ' + dl.filename)
path = os.path.join(tempfile.gettempdir(), dl.filename)
wf().logger.debug('downloading update from '
'%r to %r ...', dl.url, path)
r = web.get(dl.url)
r.raise_for_status()
r.save_to_path(path)
return path
示例4: get_downloads
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def get_downloads(repo):
"""Load available ``Download``s for GitHub repo.
.. versionadded: 1.37
Args:
repo (unicode): GitHub repo to load releases for.
Returns:
list: Sequence of `Download` contained in GitHub releases.
"""
url = build_api_url(repo)
def _fetch():
wf().logger.info('retrieving releases for %r ...', repo)
r = web.get(url)
r.raise_for_status()
return r.content
key = 'github-releases-' + repo.replace('/', '-')
js = wf().cached_data(key, _fetch, max_age=60)
return Download.from_releases(js)
示例5: download_workflow
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def download_workflow(url):
"""Download workflow at ``url`` to a local temporary file.
:param url: URL to .alfredworkflow file in GitHub repo
:returns: path to downloaded file
"""
filename = url.split("/")[-1]
if (not url.endswith('.alfredworkflow') or
not filename.endswith('.alfredworkflow')):
raise ValueError('Attachment `{0}` not a workflow'.format(filename))
local_path = os.path.join(tempfile.gettempdir(), filename)
wf().logger.debug(
'Downloading updated workflow from `%s` to `%s` ...', url, local_path)
response = web.get(url)
with open(local_path, 'wb') as output:
output.write(response.content)
return local_path
示例6: install_update
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def install_update():
"""If a newer release is available, download and install it.
:returns: ``True`` if an update is installed, else ``False``
"""
update_data = wf().cached_data('__workflow_update_status', max_age=0)
if not update_data or not update_data.get('available'):
wf().logger.info('No update available')
return False
local_file = download_workflow(update_data['download_url'])
wf().logger.info('Installing updated workflow ...')
subprocess.call(['open', local_file])
update_data['available'] = False
wf().cache_data('__workflow_update_status', update_data)
return True
示例7: install_update
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def install_update():
"""If a newer release is available, download and install it.
:returns: ``True`` if an update is installed, else ``False``
"""
key = '__workflow_latest_version'
# data stored when no update is available
no_update = {
'available': False,
'download': None,
'version': None,
}
status = wf().cached_data(key, max_age=0)
if not status or not status.get('available'):
wf().logger.info('no update available')
return False
dl = status.get('download')
if not dl:
wf().logger.info('no download information')
return False
path = retrieve_download(Download.from_dict(dl))
wf().logger.info('installing updated workflow ...')
subprocess.call(['open', path])
wf().cache_data(key, no_update)
return True
示例8: download_workflow
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def download_workflow(url):
"""Download workflow at ``url`` to a local temporary file
:param url: URL to .alfredworkflow file in GitHub repo
:returns: path to downloaded file
"""
filename = url.split("/")[-1]
if (not url.endswith('.alfredworkflow') or
not filename.endswith('.alfredworkflow')):
raise ValueError('Attachment `{0}` not a workflow'.format(filename))
local_path = os.path.join(tempfile.gettempdir(), filename)
wf().logger.debug(
'Downloading updated workflow from `{0}` to `{1}` ...'.format(
url, local_path))
response = web.get(url)
with open(local_path, 'wb') as output:
output.write(response.content)
return local_path
示例9: install_update
# 需要导入模块: import web [as 别名]
# 或者: from web import get [as 别名]
def install_update(github_slug, current_version):
"""If a newer release is available, download and install it
:param github_slug: ``username/repo`` for workflow's GitHub repo
:param current_version: the currently installed version of the
workflow. :ref:`Semantic versioning <semver>` is required.
:type current_version: ``unicode``
If an update is available, it will be downloaded and installed.
:returns: ``True`` if an update is installed, else ``False``
"""
# TODO: `github_slug` and `current_version` are both unusued.
update_data = wf().cached_data('__workflow_update_status', max_age=0)
if not update_data or not update_data.get('available'):
wf().logger.info('No update available')
return False
local_file = download_workflow(update_data['download_url'])
wf().logger.info('Installing updated workflow ...')
subprocess.call(['open', local_file])
update_data['available'] = False
wf().cache_data('__workflow_update_status', update_data)
return True