feat: added script to convert json strings to comma seperated lists
This commit is contained in:
parent
031a3dc1bc
commit
2d5e23c8a9
26
scripts/json_array_to_list
Executable file
26
scripts/json_array_to_list
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/python3
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
if __name__ == "__main__":
|
||||
# set input_string to the contents of a temporary file opened with nano
|
||||
f = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
|
||||
n = f.name
|
||||
f.close()
|
||||
subprocess.call(['nano', n])
|
||||
|
||||
with open(n, 'r') as f:
|
||||
input_string = f.read()
|
||||
Path(n).unlink()
|
||||
|
||||
# Write your code here
|
||||
input_string = input_string.strip().strip(',').strip('[').strip(']')
|
||||
|
||||
def process_part(part: str) -> str:
|
||||
part = part.strip()
|
||||
quotation = '"' if part.startswith('"') and part.endswith('"') else "'"
|
||||
return part.strip(quotation)
|
||||
|
||||
input_string = ','.join(process_part(p) for p in input_string.split(','))
|
||||
print(input_string)
|
Loading…
Reference in New Issue
Block a user