Example #1
0
def delImg(url):
    file_path = os.path.dirname(os.path.realpath(__file__)) + u'/image'
    urlHash = EncryptUtil.md5(url)
    file_name = str(urlHash) + '.jpg'
    detailPath = file_path + '\\' + file_name
    try:
        FileUtil.delFile(detailPath)
        print(u'删除图片成功:%s' % detailPath)
    except Exception as e:
        print(u'删除图片失败:%s' % str(e))
Example #2
0
def getStyle(url):
    url_hash = EncryptUtil.md5(url)
    # 先检查缓存里面的style
    file_path = getFilePath(url_hash)
    loadF = None
    try:
        if not os.path.exists(file_path):
            # 不存在,则需要下载
            styles = CssUtil.downLoad(url)
            if styles:
                with open(file_path, u'w') as loadF:
                    json.dump(
                        {
                            u'update_time':
                            datetime.datetime.now().strftime(
                                u'%Y-%m-%d %H:%M:%S'),
                            u'url':
                            url,
                            u'styles':
                            styles
                        }, loadF)
            return styles
        else:
            with open(file_path, u'r') as loadF:
                detail = json.load(loadF)
                update_time = detail[u'update_time']
                styles = detail[u'styles']
                # 如果更新时间之间相差5天,就下载
                update_time = datetime.datetime.strptime(
                    update_time, u'%Y-%m-%d  %H:%M:%S')
                now = datetime.datetime.now()
                space_day = (now - update_time).days
                if space_day >= 5:
                    # 需要重新下载
                    loadF.close()
                    FileUtil.delFile(file_path)
                    return getStyle(url)
                else:
                    # 不需要重新下载
                    return styles
    finally:
        if loadF:
            loadF.close()