File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 33import json
44import ndjson
55import argparse
6-
6+ from re import sub , escape , MULTILINE
7+ from os import remove
78
89sqlDirectory = "../sql/"
910global _engine
@@ -30,11 +31,23 @@ def main():
3031 with open (args .output , 'rb' ) as f :
3132 data = json .load (f )
3233
33- with open (args .output_ndjson , 'w+' , encoding = 'utf-8-sig' ) as f :
34+ """
35+ Next blocks are doing a nasty thing. They dump into a temporal file the contents of
36+ the data dictionary for escaping the escape character later. This generates an ndjson
37+ compatible with Postgres COPY.
38+ """
39+ with open (args .output_ndjson + '.temp' , 'w+' , encoding = 'utf-8-sig' ) as f :
3440 writer = ndjson .writer (f )
3541 for key in data :
3642 writer .writerow (data [key ])
3743
44+ with open (args .output_ndjson , 'w+' , encoding = 'utf-8-sig' ) as f :
45+ input = open (args .output_ndjson + '.temp' )
46+ f .write (sub (r'\\' ,r'\\\\' ,input .read ()))
47+ input .close ()
48+
49+ remove (args .output_ndjson + '.temp' )
50+
3851if __name__ == "__main__" :
3952 main ()
4053
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def indexDir(sqlDirectory: str, _engine: str) -> fileMap:
1818
1919 # For now, we ignore READMEs. But, we might furtherly include some documentation
2020 # artifact.
21- if key not in _fileMap and filename .removesuffix (".md" ).lower () != 'readme' :
21+ if key not in _fileMap and filename .removesuffix (".md" ).lower () not in ( 'readme' , '.gitkeep' ) :
2222 _fileMap [key ]= {'engine' : _engine }
2323 _fileMap [key ]= {'title' : sub ('[_-]' ," " , str (key )).capitalize ()}
2424
You can’t perform that action at this time.
0 commit comments