当前位置: 首页>>代码示例>>Python>>正文


Python util.download函数代码示例

本文整理汇总了Python中util.download函数的典型用法代码示例。如果您正苦于以下问题:Python download函数的具体用法?Python download怎么用?Python download使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: download_images

def download_images(course, threads_folder, thread):
    """
    Download images in given thread.
    The given thread object will be mutated.
    """
    posts = thread['posts']
    comments = thread['comments']

    thread_id = thread['id']
    thread_page = thread['start_page']

    images = []
    last_post_is_full = False
    for post in reversed(posts):
        if 'post_text' in post:
            text = post['post_text']
            text = find_images(text, images, thread_id, thread_page)
            post['post_text'] = text
            last_post_is_full = True
        elif last_post_is_full:
            break

    for comment in comments:
        text = comment['comment_text']
        text = find_images(text, images, thread_id, thread_page)
        comment['comment_text'] = text

    for url, path in images:
        path = '{}/{}'.format(threads_folder, path)
        util.download(url, path, course.get_cookie_file(), resume=True)
开发者ID:kq2,项目名称:Ricin,代码行数:30,代码来源:forum.py

示例2: download_thread

def download_thread(course, threads_folder, thread_id, page=1, post_id=None):
    """
    Download a thread.
    """
    # Download 1st page
    url = '{}/api/forum/threads/{}'.format(course.get_url(), thread_id)
    if post_id:
        url = '{}?post_id={}&position=after'.format(url, post_id)

    path = '{}/{}/{}.json'.format(threads_folder, thread_id, page)
    util.download(url, path, course.get_cookie_file())

    thread = util.read_json(path)
    download_images(course, threads_folder, thread)

    util.write_json(path, thread)

    # Download rest pages
    page = thread['start_page']
    num_page = thread['num_pages']

    if page < num_page:
        page += 1
        print 'thread page {}/{}'.format(page, num_page)

        post_id = get_next_post_id(thread['posts'])
        if post_id:
            download_thread(course, threads_folder, thread_id, page, post_id)
开发者ID:kq2,项目名称:Ricin,代码行数:28,代码来源:forum.py

示例3: _find_files

def _find_files(url, folder, cookie):
    """
    Recursively find all files in current page.
    :param url: A URL to given page.
    :param folder: A destination folder for this page.
    :param cookie: A cookie file used for downloading.
    :return: A list of files (URL, path) in current page.
    """
    files = []

    path = '{}/temp.html'.format(folder)
    util.download(url, path, cookie)

    page = util.read_file(path)
    util.remove(path)

    # recursively find all files in sub-folders
    pattern = r'<tr><td colspan="4"><a href="(.*?)">(.*?)</a>'
    for find in re.finditer(pattern, page, re.DOTALL):
        url = find.group(1)
        sub_folder = '{}/{}'.format(folder, find.group(2))
        files += _find_files(url, sub_folder, cookie)

    # find all files in this page
    pattern = r'<tr><td>(.*?)</td>.*?Embed.*?<a href="(.*?)\?.*?">Download</a>'
    for find in re.finditer(pattern, page, re.DOTALL):
        url = find.group(2)
        file_name = find.group(1)
        path = u'{}/{}'.format(folder, file_name)
        files.append((url, path))

    return files
开发者ID:kq2,项目名称:Ricin,代码行数:32,代码来源:assets.py

示例4: find_threads

def find_threads(course, forum_folder, forum_id):
    """
    Find all threads in current forum.
    Note: forum 0 has every thread!
    """
    # download the 1st page of given forum
    query = 'sort=firstposted&page=1'
    url = '{}/api/forum/forums/{}/threads?{}'
    url = url.format(course.get_url(), forum_id, query)
    path = forum_folder + '/temp.json'
    util.download(url, path, course.get_cookie_file())

    # download a huge page with all threads
    forum = util.read_json(path)
    num_threads = forum['total_threads']
    url += '&page_size={}'.format(num_threads)
    util.download(url, path, course.get_cookie_file())

    # add each thread's id to forum info
    threads = util.read_json(path)['threads']
    util.remove(path)

    path = forum_folder + '/info.json'
    forum = util.read_json(path)

    forum_threads = []
    for thread in reversed(threads):
        forum_threads.append({'id': thread['id']})

    forum['num_threads'] = num_threads
    forum['threads'] = forum_threads

    util.write_json(path, forum)
开发者ID:kq2,项目名称:Ricin,代码行数:33,代码来源:forum.py

示例5: prepare

 def prepare(self):
     if "version" in self.settings:
         version = self.settings["version"]
         download(self.url % (version, version), self.zipfile)
         unzip(self.zipfile, 'temp')
     else:
         git_clone(self.repo, 'master', 'src')
开发者ID:trevex,项目名称:coal-glm,代码行数:7,代码来源:coalfile.py

示例6: _download_old_quizzes

def _download_old_quizzes(course, item, path):
    """
    Download old version in-video quizzes.
    """
    url = '{}/admin/quiz/quiz_load?quiz_id={}'
    url = url.format(course.get_url(), item['quiz']['parent_id'])
    util.download(url, path, course.get_cookie_file())
    util.write_json(path, util.read_json(path))
开发者ID:kq2,项目名称:Ricin,代码行数:8,代码来源:video.py

示例7: _check_setuptools

    def _check_setuptools(self):

        if self.check_module("setuptools"):
            return

        url, name = URLS['ez_setup']
        util.download(url)

        self.run_py(name)
开发者ID:KDVN,项目名称:KDINDO.OpenERP,代码行数:9,代码来源:setup.py

示例8: download_stats

    def download_stats(self):
        url = self.url + '/data/stats'
        path = self.info_folder + '/stats.html'
        util.download(url, path, self.cookie_file)

        content = util.read_file(path)
        pattern = r'<h1.*?</table>'
        content = re.search(pattern, content, re.DOTALL).group(0)
        util.write_file(path, content)
开发者ID:kq2,项目名称:Ricin,代码行数:9,代码来源:course.py

示例9: _check_pyparsing

    def _check_pyparsing(self):

        if self.check_module("pyparsing"):
            return

        url, name = URLS['pyparsing']
        util.download(url, name)

        self.run_ez(name)
开发者ID:KDVN,项目名称:KDINDO.OpenERP,代码行数:9,代码来源:setup.py

示例10: prepare_negative_dataset

def prepare_negative_dataset(dataset_directory):
    negative_dataset_url = \
        'http://www.ics.uci.edu/~dramanan/papers/parse/people.zip'
    data_filepath = os.path.join(dataset_root,
                                 os.path.basename(negative_dataset_url))
    if not(os.path.exists(data_filepath)):
        download(negative_dataset_url, path=data_filepath)
    unzip(data_filepath, dataset_root)

    shutil.move(os.path.join(dataset_root, 'people_all'), dataset_directory)
开发者ID:IshitaTakeshi,项目名称:PartsBasedDetectorMod,代码行数:10,代码来源:loader_ethz.py

示例11: _check_python

    def _check_python(self):

        if os.path.exists(os.path.join(PYDIR, "python.exe")):
            return True

        url, name = URLS['python']
        util.download(url)

        print "Extracting the the python installer..."
        os.system('msiexec /a %s /qn TARGETDIR="%s"' % (name, PYDIR))
开发者ID:KDVN,项目名称:KDINDO.OpenERP,代码行数:10,代码来源:setup.py

示例12: test_download

 def test_download(self):
   # Create a temporary file name, then delete it...
   # Of course, never do this in non-testing code!!
   f = tempfile.NamedTemporaryFile()
   f.close()
   # Make sure it doesn't exist.
   assert not os.path.exists(f.name)
   # Now download, using the deleted temporary file name.
   util.download(self.url, f.name)
   assert util.sha1file(f.name) == self.sha1_gtfs
开发者ID:srthurman,项目名称:transitland-python-client,代码行数:10,代码来源:test_util.py

示例13: _load_from_url

def _load_from_url(url, to_filename):
    """ First downloads the connectome file to a file to_filename
    load it and return the reference to the connectome object
    
    Not tested.
    """
    
    from util import download    
    download(url, to_filename)
    return _load_from_cff(to_filename)
开发者ID:LTS5,项目名称:cfflib,代码行数:10,代码来源:loadsave.py

示例14: download

def download(url,name):
	downloads = __addon__.getSetting('downloads')
	if '' == downloads:
		xbmcgui.Dialog().ok(__scriptname__,__language__(30031))
		return
	stream = resolve(url)
	if stream:
		util.reportUsage(__scriptid__,__scriptid__+'/download')
		name+='.flv'
		util.download(__addon__,name,stream['url'],os.path.join(downloads,name))
开发者ID:skata890,项目名称:xbmc-doplnky,代码行数:10,代码来源:default.py

示例15: prepare

 def prepare(self):
     if "version" in self.settings:
         version = self.settings["version"]
         download(self.url % (version), self.zipfile)
         unzip(self.zipfile, 'temp')
         cp('temp/imgui-%s/' % (version), 'temp/') # TODO: mv would be cleaner
     else:
         git_clone(self.repo, 'master', 'temp')
     if "patch" in self.settings:
         with cd('temp/'):
             patch(self.settings["patch"])
开发者ID:trevex,项目名称:coal-imgui,代码行数:11,代码来源:coalfile.py


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