pythonでfoobarのalternativeを作る 6 190513 version 1

2019/05/13 22:25 by yamasyuh68
  :追加された部分   :削除された部分
(差分が大きい場合、文字単位では表示しません)
自分のPCの音楽ファイルをタグでデータベース化 6

pythonつかいづらい┐('д')┌
sqlite のwin用exe落とした
簡単、いいわ~( ´∀`)


```
import sqlite3 , glob ,os ,time

# 更新の実験

conn = sqlite3.connect(r'e:\Programs\python\_研究\database\database.db')
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()
```      

pythonつかいづらい┐('д')┌
sqlite のwin用exe落とした
簡単、いいわ~( ´∀`)

import sqlite3 , glob ,os ,time

# 更新の実験

conn = sqlite3.connect(r'e:\Programs\python\_研究\database\database.db')
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()