mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
Another update of the SQLite Extractor Script
- Added division of files
This commit is contained in:
parent
4d21dcf5b0
commit
01b997cfce
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
import sys, os, sqlite3
|
||||
import encodings
|
||||
import encodings, calendar, time
|
||||
from cStringIO import StringIO
|
||||
|
||||
home = os.environ.get("HOME")
|
||||
@ -52,6 +52,7 @@ class Convert_id(object):
|
||||
return self.__nodes[node_id]
|
||||
else:
|
||||
return("")
|
||||
|
||||
########################################################################
|
||||
## Utilities
|
||||
#
|
||||
@ -64,7 +65,8 @@ def ston(a):
|
||||
return str(a)
|
||||
else:
|
||||
return ""
|
||||
def select_all_nodes(stamp):
|
||||
|
||||
def select_all_nodes(startstamp, endstamp):
|
||||
try:
|
||||
conn = sqlite3.connect(db)
|
||||
conn.text_factory = str
|
||||
@ -73,7 +75,7 @@ def select_all_nodes(stamp):
|
||||
print(err)
|
||||
sys.exit(1)
|
||||
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:
|
||||
print(err)
|
||||
sys.exit(1)
|
||||
@ -84,6 +86,7 @@ def select_all_nodes(stamp):
|
||||
conn.close()
|
||||
return(result)
|
||||
|
||||
|
||||
# Big-endian!!!
|
||||
def readU16(strm):
|
||||
return (ord(strm.read(1)) << 16) + (ord(strm.read(1)))
|
||||
@ -121,34 +124,34 @@ def to_table(node):
|
||||
# Init bracket and basic datas
|
||||
table = '['
|
||||
table += 'id=%d' % node[0]
|
||||
table += ', actor="%s"' % Id.get_player_name(node[1])
|
||||
table += ', type=%d' % node[3]
|
||||
table += ',actor="%s"' % Id.get_player_name(node[1])
|
||||
table += ',type=%d' % node[3]
|
||||
# Inventory Manipulation
|
||||
table += ', list="%s"' % ston(node[4])
|
||||
table += ', index="%s"' % ston(node[5])
|
||||
table += ', add="%s"' % ston(node[6])
|
||||
table += ', stacknode="%s"' % Id.get_node_name(node[7])
|
||||
table += ', stackquantity="%s"' % ston(node[8])
|
||||
table += ', nodemeta=%s' % ston(node[9])
|
||||
table += ';list="%s"' % ston(node[4])
|
||||
table += ',index="%s"' % ston(node[5])
|
||||
table += ',add="%s"' % ston(node[6])
|
||||
table += ',stacknode="%s"' % Id.get_node_name(node[7])
|
||||
table += ',stackquantity="%s"' % ston(node[8])
|
||||
table += ',nodemeta=%s' % node[9]
|
||||
# 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
|
||||
table += ', oldnode="%s"' % Id.get_node_name(node[13])
|
||||
table += ', oldparam1="%s"' % node[14]
|
||||
table += ', oldparam2="%s"' % ston(node[15])
|
||||
table += ', oldmeta=%s' % decode(node[16])
|
||||
table += ';oldnode="%s"' % Id.get_node_name(node[13])
|
||||
table += ',oldparam1="%s"' % node[14]
|
||||
table += ',oldparam2="%s"' % ston(node[15])
|
||||
table += ',oldmeta=%s' % decode(node[16])
|
||||
# New node
|
||||
table += ', newnode="%s"' % Id.get_node_name(node[17])
|
||||
table += ', newparam1="%s"' % ston(node[18])
|
||||
table += ', newparam2="%s"' % ston(node[19])
|
||||
table += ', newmeta=%s' % decode(node[20])
|
||||
table += ';newnode="%s"' % Id.get_node_name(node[17])
|
||||
table += ',newparam1="%s"' % ston(node[18])
|
||||
table += ',newparam2="%s"' % ston(node[19])
|
||||
table += ',newmeta=%s' % decode(node[20])
|
||||
# Ending
|
||||
table += ']\n'
|
||||
return (table)
|
||||
|
||||
def write_list(nodes):
|
||||
def write_list(nodes, i):
|
||||
try:
|
||||
name = "database-output.txt"
|
||||
name = "rollback/database-output.%s.txt" % i
|
||||
f = open(name, "w")
|
||||
except Exception as err:
|
||||
print(err)
|
||||
@ -167,10 +170,13 @@ def write_list(nodes):
|
||||
if __name__ == '__main__':
|
||||
Id = Convert_id(db)
|
||||
#select all nodes player as set i where time >= time
|
||||
all_nodes = select_all_nodes(0) #1418613979)
|
||||
|
||||
# write in file
|
||||
# for x in range(0,len(all_nodes)):
|
||||
# print(all_nodes[x])
|
||||
write_list(all_nodes)
|
||||
timestamp = 1426978800
|
||||
i = 0
|
||||
while timestamp <= calendar.timegm(time.gmtime()):
|
||||
all_nodes = select_all_nodes(timestamp, timestamp+24*60*60)
|
||||
if len(all_nodes) > 0:
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user