我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用web.get()。
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 `{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
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
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
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
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