pythonつかいづらい┐('д')┌
sqliteでdbいじるときは意図したとおりになっているか確認が必須だが、pythonだといちいち面倒
素だとselect文ですぐ結果表示されるはずなのにpythonはexecuteしたあとでfetchで取り出してprintしなくちゃイケない
で、sqlite のwin用exeを落とした
コンソールだけど簡単で、いいわ~( ´∀`)
アーカイブにはexeが三つ入ってるがとりあえず本体だけ解凍してdbのフォルダに置いたらすぐ使えた
当たり前だけど解説サイトの通りでselectしてやればすぐ結果がわかる
二段階方式の一段階目だけのコード書いてみた
新規時も更新時も使えるように
import sqlite3 , glob ,os ,time
# 更新の実験
conn = sqlite3.connect(<pass>)
c = conn.cursor()
sel='select mtime from musics where fullpath = ?'
fo=r'i:\Music\jazz\**'
count={'all':0 , 'file':0 , 'same':0 , 'diff':0 ,'none':0 , 'new':0}
start = time.time()
for p in glob.iglob(fo , recursive=True):
count['all'] += 1
if os.path.isfile(p):
count['file'] += 1
try:
c.execute( "INSERT INTO musics (fullpath) VALUES (?)" , (p, ))
count['new'] += 1
except:
c.execute('select mtime from musics where fullpath = ?',(p, ))
res=c.fetchone()
nmtime=os.path.getmtime(p)
if res :
if res[0]==nmtime :
count['same'] += 1
else :
count['diff'] += 1
print(p)
c.execute('update musics set mtime = ? where fullpath = ? ',( None, p ))
elapsed_time = time.time() - start
print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
print(count)
conn.commit()
conn.close()
m = mutagen.File(path, easy=True)
m['title']
-->[u'Sunshine Smile']
m['artist']
-->[u'Adorable']
m['album']
-->[u'Against Perfection']