Last active
August 7, 2016 00:28
-
-
Save BlackVoid/b6f0ba1dd7e8ce46d7f9 to your computer and use it in GitHub Desktop.
Converts sqlite database for pointshop to mysql (outputs sql file)
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
# -*- coding: utf-8 -*- | |
import sqlite3 | |
conn = sqlite3.connect('sv.db') | |
c = conn.cursor() | |
sql = """SELECT | |
`uid`, | |
(SELECT value FROM `playerpdata` WHERE `infoid` = (`uid` || '[PS_Points]')) as points, | |
(SELECT value FROM `playerpdata` WHERE `infoid` = (`uid` || '[PS_Items]')) as items | |
FROM | |
( | |
SELECT | |
substr(`infoid`, 1, length(`infoid`)-11) as `uid` | |
FROM | |
`playerpdata` | |
WHERE | |
substr(`infoid`, -1, -9) = 'PS_Points' | |
) as p""" | |
c.execute(sql) | |
players = c.fetchall() | |
with open("output.sql", "w+") as f: | |
for k,v in enumerate(players): | |
items = v[2].replace("\"", "\\\"") if v[2] is not None else "{}" | |
f.write("INSERT INTO `pointshop_data` VALUES (%s, %s,\"%s\");\n" % (v[0], v[1], items,)) | |
if (k+1) % 100 == 0: | |
print("%s players converted." % (k+1,)) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment