import os import sys import dataset import codecs fname_dict={} #fulllst=['#31','#32','#33','#34','#35','#36','#37','#38','#39','#40','#41','#42'] fulllst=['#49','#50','#51','#52','#53','#54','#55'] fr=codecs.open('c:/tmp/ytfiles.csv','r','utf-8') lines=fr.readlines() fr.close() ## .mp4 -> yid fname_yiddict={} for l in lines: elmts=l.split(',') if len(elmts[2])>10: fname_yiddict[elmts[0].lower().replace('\r','').replace('\n','')]=elmts[2].replace('\r','').replace('\n','').replace("http://youtu.be/",'').replace("https://youtu.be/",'') for lst_elmt in fulllst: lst=os.listdir('O:\\【完整版】幸福空間節目\\'+lst_elmt) for l in lst: fname_dict[l]='O:\\【完整版】幸福空間節目\\'+lst_elmt+"\\"+l print(l) print('O:\\【完整版】幸福空間節目\\'+lst_elmt+"\\"+l) db2 = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4') table=db2['yt_tasks2'] db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@127.0.0.1:13317/xoops?charset=utf8mb4') # yid -> detail yiddict={} cursor=db.query('select youtube_video_id,title,description from youtube_list') title=None desc=None for c in cursor: # print(c['youtube_video_id']) yiddict[c['youtube_video_id']]=c # title=c['title'] # desc=c['description'] for k,v in fname_yiddict.items(): # print(k) # print(v) if yiddict.get(v): if fname_dict.get(k): table.insert({'fname':k,'path':fname_dict[k],'yid':yiddict[v]['youtube_video_id'],'title':yiddict[v]['title'],'desc':yiddict[v]['description']}) print(k) print(fname_dict[k]) print(yiddict[v]['youtube_video_id']) print(yiddict[v]['title']) #print(lst)