-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateInteractiveUrl.py
More file actions
52 lines (42 loc) · 1.51 KB
/
Copy pathUpdateInteractiveUrl.py
File metadata and controls
52 lines (42 loc) · 1.51 KB
1
import fileinputimport sysimport argparse'''{ "startNodeId": "1", "interactiveUrl":"", "conditionUrl": "", "eventUrl": ""}'''FILE_PATH = '/Users/kylece/Downloads/mock.json'INTERACTIVE_KEY = '"interactiveUrl"'CONDITION_KEY = '"conditionUrl"'EVENT_KEY = '"eventUrl"'URL_JSON_FORMAT = '%s:"%s"'SPLIT = ','def replace_all(file, interactive_url=None, condition_url=None, event_url=None): if interactive_url is None and condition_url is None and event_url is None: print('no valid argument') return for line in fileinput.input(file, inplace=1): if INTERACTIVE_KEY in line: line = replace_line(line, INTERACTIVE_KEY, interactive_url) elif CONDITION_KEY in line: line = replace_line(line, CONDITION_KEY, condition_url) elif EVENT_KEY in line: line = replace_line(line, EVENT_KEY, event_url) sys.stdout.write(line)def replace_line(origin, key, target): line = URL_JSON_FORMAT % (key, '' if target is None else target) + \ (SPLIT if origin.strip().endswith(',') else '') + '\n' return lineif __name__ == '__main__': parser = argparse.ArgumentParser(description='Update url in mock.json.') parser.add_argument('-i', help='interactive url') parser.add_argument('-c', help='condition url') parser.add_argument('-e', help='event url') args = parser.parse_args() print(args) argv = sys.argv replace_all(FILE_PATH, interactive_url=args.i, condition_url=args.c, event_url=args.e)