Another update of the SQLite Extractor Script

- Added division of files
This commit is contained in:
LeMagnesium 2015-07-09 22:09:27 +02:00
parent 4d21dcf5b0
commit 01b997cfce
1 changed files with 144 additions and 138 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import sys, os, sqlite3 import sys, os, sqlite3
import encodings import encodings, calendar, time
from cStringIO import StringIO from cStringIO import StringIO
home = os.environ.get("HOME") home = os.environ.get("HOME")
@ -52,6 +52,7 @@ class Convert_id(object):
return self.__nodes[node_id] return self.__nodes[node_id]
else: else:
return("") return("")
######################################################################## ########################################################################
## Utilities ## Utilities
# #
@ -64,7 +65,8 @@ def ston(a):
return str(a) return str(a)
else: else:
return "" return ""
def select_all_nodes(stamp):
def select_all_nodes(startstamp, endstamp):
try: try:
conn = sqlite3.connect(db) conn = sqlite3.connect(db)
conn.text_factory = str conn.text_factory = str
@ -73,7 +75,7 @@ def select_all_nodes(stamp):
print(err) print(err)
sys.exit(1) sys.exit(1)
try: try:
cur.execute("SELECT * FROM action WHERE timestamp >=:stamp", {"stamp":stamp}) cur.execute("SELECT * FROM action WHERE timestamp >=:startstamp AND timestamp < :endstamp", {"startstamp":startstamp, "endstamp":endstamp})
except sqlite3.OperationalError as err: except sqlite3.OperationalError as err:
print(err) print(err)
sys.exit(1) sys.exit(1)
@ -84,6 +86,7 @@ def select_all_nodes(stamp):
conn.close() conn.close()
return(result) return(result)
# Big-endian!!! # Big-endian!!!
def readU16(strm): def readU16(strm):
return (ord(strm.read(1)) << 16) + (ord(strm.read(1))) return (ord(strm.read(1)) << 16) + (ord(strm.read(1)))
@ -121,34 +124,34 @@ def to_table(node):
# Init bracket and basic datas # Init bracket and basic datas
table = '[' table = '['
table += 'id=%d' % node[0] table += 'id=%d' % node[0]
table += ', actor="%s"' % Id.get_player_name(node[1]) table += ',actor="%s"' % Id.get_player_name(node[1])
table += ', type=%d' % node[3] table += ',type=%d' % node[3]
# Inventory Manipulation # Inventory Manipulation
table += ', list="%s"' % ston(node[4]) table += ';list="%s"' % ston(node[4])
table += ', index="%s"' % ston(node[5]) table += ',index="%s"' % ston(node[5])
table += ', add="%s"' % ston(node[6]) table += ',add="%s"' % ston(node[6])
table += ', stacknode="%s"' % Id.get_node_name(node[7]) table += ',stacknode="%s"' % Id.get_node_name(node[7])
table += ', stackquantity="%s"' % ston(node[8]) table += ',stackquantity="%s"' % ston(node[8])
table += ', nodemeta=%s' % ston(node[9]) table += ',nodemeta=%s' % node[9]
# Position # Position
table += ', x=%s, y=%s, z=%s' % (node[10], node[11], node[12]) table += ';x=%s, y=%s, z=%s' % (node[10], node[11], node[12])
# Old node # Old node
table += ', oldnode="%s"' % Id.get_node_name(node[13]) table += ';oldnode="%s"' % Id.get_node_name(node[13])
table += ', oldparam1="%s"' % node[14] table += ',oldparam1="%s"' % node[14]
table += ', oldparam2="%s"' % ston(node[15]) table += ',oldparam2="%s"' % ston(node[15])
table += ', oldmeta=%s' % decode(node[16]) table += ',oldmeta=%s' % decode(node[16])
# New node # New node
table += ', newnode="%s"' % Id.get_node_name(node[17]) table += ';newnode="%s"' % Id.get_node_name(node[17])
table += ', newparam1="%s"' % ston(node[18]) table += ',newparam1="%s"' % ston(node[18])
table += ', newparam2="%s"' % ston(node[19]) table += ',newparam2="%s"' % ston(node[19])
table += ', newmeta=%s' % decode(node[20]) table += ',newmeta=%s' % decode(node[20])
# Ending # Ending
table += ']\n' table += ']\n'
return (table) return (table)
def write_list(nodes): def write_list(nodes, i):
try: try:
name = "database-output.txt" name = "rollback/database-output.%s.txt" % i
f = open(name, "w") f = open(name, "w")
except Exception as err: except Exception as err:
print(err) print(err)
@ -167,10 +170,13 @@ def write_list(nodes):
if __name__ == '__main__': if __name__ == '__main__':
Id = Convert_id(db) Id = Convert_id(db)
#select all nodes player as set i where time >= time #select all nodes player as set i where time >= time
all_nodes = select_all_nodes(0) #1418613979) timestamp = 1426978800
i = 0
# write in file while timestamp <= calendar.timegm(time.gmtime()):
# for x in range(0,len(all_nodes)): all_nodes = select_all_nodes(timestamp, timestamp+24*60*60)
# print(all_nodes[x]) if len(all_nodes) > 0:
write_list(all_nodes) write_list(all_nodes, i)
i += 1
print("%s to %s => %s entries" % (timestamp, timestamp+24*60*60, len(all_nodes)))
timestamp += 24*60*60