diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2024-01-20 12:31:58 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2024-01-20 12:31:58 -0500 |
| commit | e2a0cf2a79b43f9f86b74270f3d96fe300687804 (patch) | |
| tree | a87edf55f81e78f4d0968d6f006562090260e068 /scripts/webhook.py | |
| parent | ec83443853116b07f18fbef8c6de31cf157939a0 (diff) | |
| download | dotfiles-e2a0cf2a79b43f9f86b74270f3d96fe300687804.tar.gz dotfiles-e2a0cf2a79b43f9f86b74270f3d96fe300687804.tar.xz | |
Cleanup unused files and code.
Diffstat (limited to 'scripts/webhook.py')
| -rwxr-xr-x | scripts/webhook.py | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/scripts/webhook.py b/scripts/webhook.py deleted file mode 100755 index 3db70a8..0000000 --- a/scripts/webhook.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python3 -import requests, json, sys - -expected_status = 204 -url = "" -# Default for discord, easy enough to override -msg = { - "username": "{hostname} script", - "content": "```{stdin}```", -} - -customVars = {} - -def merge_dicts(*dict_args): - result = {} - for dictionary in dict_args: - result.update(dictionary) - return result - -def template(msg, fmt): - out = {} - for k, v in msg.items(): - if isinstance(v, dict): - out[k] = template(v, fmt) - else: - out[k] = v.format(**fmt) - return out - - -def help(): - print("Usage: {} [-m msg] [-u url] [-s expected_status] [-V var content]...".format(sys.argv[0])) - print("A small python script to send webhooks easily from the command line utilizing arguments and stdin") - print("Only requrement is the requests library") - print("Defaults:") - print("\tmsg: " + json.dumps(msg)) - print("\turl: " + url) - print("\texpected_status: ", expected_status) - print("") - print("The [-V var content] arguments allow you to specifiy custom vars to be overridden in the json msg.") - sys.exit(2) - -n = 1 -while n < len(sys.argv): - if sys.argv[n] == "-u": - url = sys.argv[n+1] - n += 2 - elif sys.argv[n] == "-m": - msg = json.loads(sys.argv[n+1]) - n += 2 - elif sys.argv[n] == "-s": - expected_status = int(sys.argv[n+1]) - n += 2 - elif sys.argv[n] == "-V": - customVars[sys.argv[n+1]] = sys.argv[n+2] - n += 3 - else: - help() - -if url == "": - sys.stderr.write("No URL provided\n") - help() - -msg2 = template(msg, merge_dicts(customVars , {"stdin": sys.stdin.read()})) -r = requests.post(url, json=msg2) - -if r.status_code != expected_status: - print(r) - print(r.text) - sys.exit(1) - |
