Created
October 4, 2022 17:46
-
-
Save dword4/588ceef77f667dceaa29461cf1941db6 to your computer and use it in GitHub Desktop.
very ugly and simplistic way to let people create plugins with only some json
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
#!/usr/bin/env python3 """ mockup language engine for plugins """ | |
import json | |
js = '{"name":"command_name", "prompt": [{"question": "where do you want to ping", "var": "dest"},{"question": "ping from", "var": "src"}], "handler": "some_function", "query": "ping $dest from $src"}' | |
j = json.loads(js) | |
def some_function(j): | |
print(f"command: {j['name']}") | |
answer = {} | |
for q in j['prompt']: | |
answer[q['var']] = input(f"{q['question']}: ") | |
print(f"q before interpret: {j['query']}") | |
for key, value in answer.items(): | |
if f"${key}" in j['query']: | |
j['query'] = j['query'].replace(f"${key}", value) | |
print(j['query']) | |
some_function(j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment