Created
December 4, 2020 20:37
-
-
Save mralext20/b27ab794ebf9f17d6b932b08f0b3d2d2 to your computer and use it in GitHub Desktop.
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
import json | |
import sqlite3 | |
file = "data.db" | |
table = "booths" | |
rows = ["title", "description", "video", "school"] | |
columnForFileName = 'title' | |
targetDir = "export" | |
conn = sqlite3.connect(file) | |
def transform(row): | |
ret = {} | |
idex = 0 | |
for i in rows: | |
ret[i] = row[idex] | |
idex += 1 | |
return ret | |
if __name__ == "__main__": | |
for row in conn.execute(f"""SELECT {', '.join(rows)} FROM {table}"""): | |
row = transform(row) | |
with open(f"{targetDir}/{row[columnForFileName]}.json", 'w') as f: | |
json.dump(row, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment