Created
May 12, 2022 14:34
-
-
Save Algo-ryth-mix/c0a462cb983039912326580bcddd7085 to your computer and use it in GitHub Desktop.
out of 2 json files make one
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 argh | |
import json | |
import io | |
## very simple json patcher | |
## make sure to pip install argh | |
@argh.arg('basefile',help='path to the file you want to patch') | |
@argh.arg('patchfile',help='path to the file you want to patch BASEFILE with') | |
def main(basefile: str, patchfile: str): | |
with io.open(basefile,'r',encoding='utf-8') as basef: | |
base = json.loads(basef.read()) | |
with io.open(patchfile,'r', encoding='utf-8') as patchf: | |
patch = json.loads(patchf.read()) | |
patched = { **base , **patch } | |
with io.open(basefile,'w',encoding='utf-8') as patchedf: | |
patchedf.write(json.dumps(patched)) | |
if __name__ == "__main__": | |
argh.dispatch_command(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment