Created
January 18, 2009 18:17
-
-
Save diwakergupta/48719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# copy-ratings.py | |
# @Author: Diwaker Gupta (diwaker@floatingsun.net) | |
# @Last Change: 2008-05-28 | |
import os | |
import sys | |
import optparse | |
from pysqlite2 import dbapi2 as sqlite | |
parser = optparse.OptionParser("%prog [options] old-collection new-collection") | |
parser.add_option("--verbose", "-v", action = "store_true", dest = "verbose") | |
(options, args) = parser.parse_args() | |
if len(args) < 2: | |
parser.print_help() | |
sys.exit(1) | |
old_conn = sqlite.connect(args[0]) | |
old_conn.text_factory = str | |
old = old_conn.cursor() | |
new_conn = sqlite.connect(args[1]) | |
new_conn.text_factory = str | |
new = new_conn.cursor() | |
new.execute("select url,uniqueid,deviceid from uniqueid") | |
songs = new.fetchall() | |
for (url, uniqueid,deviceid) in songs: | |
old.execute("select * from statistics where uniqueid='%s'" % (uniqueid)) | |
vals = old.fetchone() | |
if vals != None: | |
oldurl, olddeviceid, createdate, accessdate, percentage, rating, playcounter, olduniqueid, deleted = vals | |
new.execute("insert into statistics values (?,?,?,?,?,?,?,?,?)", | |
(url, deviceid, createdate, accessdate, percentage, rating, playcounter, uniqueid, deleted)) | |
new_conn.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment