mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-02 09:49:36 +01:00
fixed db closing issue w/ python 2.7
This commit is contained in:
@@ -42,20 +42,26 @@ def itunesImport(pathtoxml):
|
|||||||
releaseid = u.extractUuid(release.id)
|
releaseid = u.extractUuid(release.id)
|
||||||
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
||||||
results = ws.Query().getReleaseById(releaseid, inc)
|
results = ws.Query().getReleaseById(releaseid, inc)
|
||||||
|
|
||||||
for event in results.releaseEvents:
|
for event in results.releaseEvents:
|
||||||
|
|
||||||
if event.country == 'US':
|
if event.country == 'US':
|
||||||
|
|
||||||
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||||
|
|
||||||
latestrelease = c.fetchall()
|
latestrelease = c.fetchall()
|
||||||
|
|
||||||
if latestrelease[0][0] > latestrelease[0][1]:
|
if latestrelease[0][0] > latestrelease[0][1]:
|
||||||
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
for track in results.tracks:
|
for track in results.tracks:
|
||||||
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
c.close()
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
c.close()
|
||||||
28
updater.py
28
updater.py
@@ -10,46 +10,60 @@ def dbUpdate():
|
|||||||
conn=sqlite3.connect(database)
|
conn=sqlite3.connect(database)
|
||||||
c=conn.cursor()
|
c=conn.cursor()
|
||||||
c.execute('SELECT ArtistID from artists WHERE Status="Active"')
|
c.execute('SELECT ArtistID from artists WHERE Status="Active"')
|
||||||
|
|
||||||
activeartists = c.fetchall()
|
activeartists = c.fetchall()
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
while i < len(activeartists):
|
while i < len(activeartists):
|
||||||
|
|
||||||
artistid = activeartists[i][0]
|
artistid = activeartists[i][0]
|
||||||
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), ratings=False, releaseGroups=False)
|
inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), ratings=False, releaseGroups=False)
|
||||||
artist = ws.Query().getArtistById(artistid, inc)
|
artist = ws.Query().getArtistById(artistid, inc)
|
||||||
print '''now working on %s''' % artist.name
|
|
||||||
for release in artist.getReleases():
|
for release in artist.getReleases():
|
||||||
|
|
||||||
releaseid = u.extractUuid(release.id)
|
releaseid = u.extractUuid(release.id)
|
||||||
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
||||||
results = ws.Query().getReleaseById(releaseid, inc)
|
results = ws.Query().getReleaseById(releaseid, inc)
|
||||||
print '''now working on %s by %s''' % (results.title, artist.name)
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
for event in results.releaseEvents:
|
for event in results.releaseEvents:
|
||||||
|
|
||||||
if event.country == 'US':
|
if event.country == 'US':
|
||||||
|
|
||||||
if (u.extractUuid(results.id) in x for x in activeartists):
|
if (u.extractUuid(results.id) in x for x in activeartists):
|
||||||
print '''%s is already in the database''' % results.title
|
|
||||||
c.execute('UPDATE albums SET AlbumASIN="%s", ReleaseDate="%s" WHERE AlbumID="%s"' % (results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id)))
|
c.execute('UPDATE albums SET AlbumASIN="%s", ReleaseDate="%s" WHERE AlbumID="%s"' % (results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id)))
|
||||||
print ''' updated asin and release date for %s ''' % results.title
|
|
||||||
for track in results.tracks:
|
for track in results.tracks:
|
||||||
c.execute('UPDATE tracks SET TrackDuration="%s" WHERE AlbumID="%s" AND TrackID="%s"' % (track.duration, u.extractUuid(results.id), u.extractUuid(track.id)))
|
c.execute('UPDATE tracks SET TrackDuration="%s" WHERE AlbumID="%s" AND TrackID="%s"' % (track.duration, u.extractUuid(results.id), u.extractUuid(track.id)))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
print '''%s has been updated''' % results.title
|
|
||||||
else:
|
else:
|
||||||
print '''%s is new, adding it''' % results.title
|
|
||||||
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||||
|
|
||||||
latestrelease = c.fetchall()
|
latestrelease = c.fetchall()
|
||||||
|
|
||||||
if latestrelease[0][0] > latestrelease[0][1]:
|
if latestrelease[0][0] > latestrelease[0][1]:
|
||||||
|
|
||||||
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for track in results.tracks:
|
for track in results.tracks:
|
||||||
|
|
||||||
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
print '''%s has been added''' % release.title
|
|
||||||
else:
|
else:
|
||||||
print '''%s is not a US release''' % results.title
|
print '''%s is not a US release''' % results.title
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
c.close()
|
c.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
12
webServer.py
12
webServer.py
@@ -195,30 +195,36 @@ class Headphones:
|
|||||||
if any(artistid in x for x in artistlist):
|
if any(artistid in x for x in artistlist):
|
||||||
page = [templates._header]
|
page = [templates._header]
|
||||||
page.append('''%s has already been added. Go <a href="/">back</a>.''' % artist.name)
|
page.append('''%s has already been added. Go <a href="/">back</a>.''' % artist.name)
|
||||||
|
c.close()
|
||||||
return page
|
return page
|
||||||
|
|
||||||
else:
|
else:
|
||||||
c.execute('INSERT INTO artists VALUES( ?, ?, ?, CURRENT_DATE, ?)', (artistid, artist.name, artist.sortName, 'Active'))
|
c.execute('INSERT INTO artists VALUES( ?, ?, ?, CURRENT_DATE, ?)', (artistid, artist.name, artist.sortName, 'Active'))
|
||||||
|
|
||||||
for release in artist.getReleases():
|
for release in artist.getReleases():
|
||||||
releaseid = u.extractUuid(release.id)
|
releaseid = u.extractUuid(release.id)
|
||||||
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True)
|
||||||
results = ws.Query().getReleaseById(releaseid, inc)
|
results = ws.Query().getReleaseById(releaseid, inc)
|
||||||
time.sleep(0.6)
|
time.sleep(0.6)
|
||||||
|
|
||||||
for event in results.releaseEvents:
|
for event in results.releaseEvents:
|
||||||
if event.country == 'US':
|
if event.country == 'US':
|
||||||
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
c.execute('INSERT INTO albums VALUES( ?, ?, ?, ?, ?, CURRENT_DATE, ?, ?)', (artistid, results.artist.name, results.title, results.asin, results.getEarliestReleaseDate(), u.extractUuid(results.id), 'Skipped'))
|
||||||
conn.commit()
|
|
||||||
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
c.execute('SELECT ReleaseDate, DateAdded from albums WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||||
latestrelease = c.fetchall()
|
latestrelease = c.fetchall()
|
||||||
|
|
||||||
if latestrelease[0][0] > latestrelease[0][1]:
|
if latestrelease[0][0] > latestrelease[0][1]:
|
||||||
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
c.execute('UPDATE albums SET Status = "Wanted" WHERE AlbumID="%s"' % u.extractUuid(results.id))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for track in results.tracks:
|
for track in results.tracks:
|
||||||
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
c.execute('INSERT INTO tracks VALUES( ?, ?, ?, ?, ?, ?, ?, ?)', (artistid, results.artist.name, results.title, results.asin, u.extractUuid(results.id), track.title, track.duration, u.extractUuid(track.id)))
|
||||||
conn.commit()
|
|
||||||
c.close()
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
raise cherrypy.HTTPRedirect("/")
|
raise cherrypy.HTTPRedirect("/")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user