Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions csv_import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

rm -rf tmp
mkdir tmp
cd tmp
dolt init
dolt sql < dolt-schema.sql
dolt table import -u books oreilly_mod.csv
4 changes: 2 additions & 2 deletions dolt-schema.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE TABLE books (
`id` LONGTEXT NOT NULL,
`ourn` LONGTEXT,
`isbn` INTEGER,
`isbn` bigint,
`last_modified_time` DATETIME,
`issued` DATETIME,
`format` TEXT,
Expand All @@ -26,4 +26,4 @@ CREATE TABLE books (
`topics` JSON,
`topics_payload` JSON,
`minutes_required` INTEGER
)
)
21 changes: 21 additions & 0 deletions json_conv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import json
import os
import csv
def main():
j = json.load(open("oreilly.json"))
tostr = ["authors", "publishers", "topics", "topics_payload"]
for o in j:
for f in tostr:
o[f] = json.dumps(o[f])
with open(os.path.join("oreilly_mod.json"), 'a+', encoding='utf-8', errors="replace") as outfile:
json.dump(j, outfile, indent=2)
field_names = []
for k in j[0]:
field_names.append(k)
with open('oreilly_mod.csv', 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames = field_names)
writer.writeheader()
writer.writerows(j)

if __name__ == "__main__":
main()
Loading