• 离线节目单合成--Python


    import os,re,shutil

    def get_filelist(dir):
        t1='{"computerPlayId":'
        t2=' ,"computerPlayListArray": '
        t3=', "propertyPlayId":"", "propertyPlayListArray": []}'
        listid=[]
        listtext=[]
        for root, dirs, files in os.walk(dir):
            for d in dirs:
                path1=os.path.join(root,d)
                print(path1)
                for root1,dir1,files1 in os.walk(path1):
                    for f in files1:
                        path2=os.path.join(root1,f)
                        print(path2)
                        if f=="playList.txt":
                            with open(path2,'r',encoding='utf8')as file1:
                                t=file1.read()
                                matchobj=re.match('{"play_list_id":(d+?),',t)
                                id=matchobj.group(1)
                                listid.append(id)
                                listtext.append(t)
                        elif f!="pubKeyMsgPwd.txt":
                            path3="D:\离线节目单合成\material\"+f
                            shutil.copy(path2,path3)
        idString=""
        textString=""
        for i in listid:
            idString=idString+i+','
        idString=idString.rstrip(',')
        print(idString)
        t1=t1+'"'+idString+'"'
        for j in listtext:
            textString=textString+','+j
        textString=textString.strip(',')
        print(textString)
        t2=t2+'['+textString+']'
        t=t1+t2+t3
        
        with open("D:\离线节目单合成\material\playList.txt",'w')as f:
            
            f.write(t)
                             

    if __name__ == "__main__":
        get_filelist('D:\离线节目单合成\节目单')

  • 相关阅读:
    js json和对象互相转换
    github配置和git学习
    sea.js,spm学习
    less学习-语法(二)
    less学习-浏览器端编译(一)
    grunt-mac上安装运行构建工具的总结(一)
    Advice from an Old Programmer
    scikit-FEM-例2-用Morley元在方形区域上解板弯曲问题
    scikit-FEM-例1-求解Possion边值问题
    在shell脚本中调用sqlplus 分类: H2_ORACLE 2013-06-23 13:01 1437人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/ada-luo/p/14866235.html
Copyright © 2020-2023  润新知