parse_infos.py 文件源码

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

项目:chrome-extensions-archive 作者: mdamien 项目源码 文件源码
def extract_manifest_of_file(crx_file):
    debug = False
    if os.path.isfile(crx_file):
        size = os.path.getsize(crx_file)
        if size == 0:
            print('###################!!!! fucking empty downloads', crx_file)
            return
        try:
            with ZipFile(crx_file) as myzip:
                if debug:
                    # """ #save file to debug later
                    source = myzip.open('manifest.json')
                    target = open('lol.json', "wb")
                    with source, target:
                        shutil.copyfileobj(source, target)
                    #"""
                with myzip.open('manifest.json') as myfile:
                    text = myfile.read()
                    #if debug: print(text)
                    try:
                        text = text.decode('utf-8-sig')
                    except:
                        text = text.decode('latin-1')
                    if debug: print(text)
                    try:
                        return json.loads(text, strict=False)
                    except Exception as e:
                        print(e)
                        text = uncomment(text)
                        return json.loads(text, strict=False)
        except BadZipFile:
            print('fucking interrupted downloads')
    else:
        print(crx_file,'does not exist')
    #TODO: add filesize
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号