download_planet_python.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:python-station-backend 作者: itielshwartz 项目源码 文件源码
def download_posts(output_file, max_page_to_download=None):
    with open(output_file, "w") as f:  # open the output file
        pages_to_download_itr = range(1, max_page_to_download + 1) if max_page_to_download else itertools.count(1)
        for i in pages_to_download_itr:  # start itrate over the pages
            url = BASE_URL.format(i)
            logging.info("fetching %s", format(url))
            page_data = download_with_retry(url)
            if should_stop_page(page_data):  # validate it's not the last page
                return logging.info("Finished Downloading all data")
            f.write(json.dumps(page_data) + "\n")  # write page as jsonline
            logging.info("finished %s", format(url))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号