Skip to content

Instantly share code, notes, and snippets.

@jarekt
Created February 20, 2022 18:33
Show Gist options
  • Save jarekt/f07c6f5e64deecc0eb965b5ebd9db9d0 to your computer and use it in GitHub Desktop.
Save jarekt/f07c6f5e64deecc0eb965b5ebd9db9d0 to your computer and use it in GitHub Desktop.
create a csv file to be imported into mca selector from coreprotect database
import sqlite3
from contextlib import redirect_stdout
ro_db = lambda a : "file:" + a + "?mode=ro"
db = sqlite3.connect("file:out.db?mode=ro", uri=True)
db.set_trace_callback(print)
c = db.cursor()
to_save = c.execute("""
SELECT DISTINCT x >> 4, z >> 4 FROM co_block
LEFT JOIN co_user ON co_block.user = co_user.id
WHERE (action = 0 OR action = 1) AND wid = 1 AND co_user.uuid IS NOT NULL
""").fetchall()
to_print = ""
for row in to_save:
to_print += "%d;%d;%d;%d\n" % (row[0] >> 5, row[1] >> 5, row[0], row[1])
with open('out.csv', 'w') as f:
with redirect_stdout(f):
print(to_print)
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment