當前位置: 首頁>>代碼示例>>Python>>正文


Python web.get方法代碼示例

本文整理匯總了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 
開發者ID:TKkk-iOSer,項目名稱:wechat-alfred-workflow,代碼行數:26,代碼來源:update.py

示例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 
開發者ID:TKkk-iOSer,項目名稱:wechat-alfred-workflow,代碼行數:22,代碼來源:update.py

示例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 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:27,代碼來源:update.py

示例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) 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:25,代碼來源:update.py

示例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 
開發者ID:ecbrodie,項目名稱:pomodoro-alfred,代碼行數:26,代碼來源:update.py

示例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 
開發者ID:ecbrodie,項目名稱:pomodoro-alfred,代碼行數:22,代碼來源:update.py

示例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 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:33,代碼來源:update.py

示例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 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:28,代碼來源:update.py

示例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 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:31,代碼來源:update.py


注:本文中的web.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。