1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# -*- coding: utf8 -*-
#
# Copyright (C) 2014 Evol Online
# Author: Andrei Karas (4144)
import re
from code.fileutils import readFile
from code.stringutils import stripNewLine
from code.server.dbitem import Item
def convertStorage():
srcFile = "olddb/storage.txt"
dstFile = "newdb/storage.sql"
fieldsSplit = re.compile("\t")
comaSplit = re.compile(",")
spaceSplit = re.compile(" ")
tpl = readFile("templates/storage.sql")
firstLine = True
with open(dstFile, "w") as w:
w.write(tpl)
w.write("INSERT INTO `storage` VALUES ")
with open(srcFile, "r") as r:
for line in r:
if line[:2] == "//":
continue
rows = fieldsSplit.split(line)
if len(rows) == 2:
continue
if len(rows) != 3:
print("wrong storage.txt line: " + stripNewLine(line))
continue
tmp = comaSplit.split(rows[0])
accountId = tmp[0]
# storage_amount = tmp[1]
data = spaceSplit.split(rows[1])
for itemStr in data:
if itemStr == "":
continue
tmp = comaSplit.split(itemStr)
item = Item()
item.unknownId = tmp[0]
item.itemId = tmp[1]
item.amount = tmp[2]
item.equip = tmp[3]
item.color = tmp[4]
item.refine = tmp[5]
item.attribute = tmp[6]
item.card0 = tmp[7]
item.card1 = tmp[8]
item.card2 = tmp[9]
item.card3 = "0"
if firstLine == False:
w.write(",\n")
else:
firstLine = False
w.write(("({id},{account_id},{nameid},{amount},{equip},{identify}," +
"{refine},{attribute},{card0},{card1},{card2},{card3}," +
"{expire_time},{bound},{unique_id})").format(
id = 0,
account_id = accountId,
nameid = item.itemId,
amount = item.amount,
equip = item.equip,
identify = "1",
refine = item.refine,
attribute = item.attribute,
card0 = "0",
card1 = "0",
card2 = "0",
card3 = "0",
expire_time = "0",
bound = "0",
unique_id = "0"
))
w.write("\n")
|