Skip to content

Instantly share code, notes, and snippets.

@dword4
Created October 4, 2022 17:46
Show Gist options
  • Save dword4/588ceef77f667dceaa29461cf1941db6 to your computer and use it in GitHub Desktop.
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
#!/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