Skip to content

Instantly share code, notes, and snippets.

@mralext20
Created December 4, 2020 20:37
Show Gist options
  • Save mralext20/b27ab794ebf9f17d6b932b08f0b3d2d2 to your computer and use it in GitHub Desktop.
Save mralext20/b27ab794ebf9f17d6b932b08f0b3d2d2 to your computer and use it in GitHub Desktop.
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