m_runtastic.py 文件源码

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

项目:centr 作者: ibiBgOR 项目源码 文件源码
def check_download_session(url, download_dir, cookies):
    r = requests.head(url, cookies=cookies)
    if r.status_code != 200 or 'Content-Disposition' not in r.headers:
        return False
    m = re.search('filename="(.+)"', r.headers['Content-Disposition'])
    if not m:
        return False
    f = m.group(1)
    filename = os.path.join(download_dir, f)
    if os.path.isfile(filename):
        return True
    # get it
    print "Fetching %s" % f
    r2 = requests.get(url, cookies=cookies)
    if r2.status_code != 200:
        return False
    with open(filename, 'wb') as f:
        f.write(r2.content)
    return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号