• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

离线节目单合成–Python

开发技术 开发技术 1周前 (06-09) 11次浏览

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:\离线节目单合成\节目单’)


程序员灯塔
转载请注明原文链接:离线节目单合成–Python
喜欢 (0)