From 4b41a107b02d53156509829e3c4f8ffa3f05f149 Mon Sep 17 00:00:00 2001 From: user2 Date: Sat, 29 Jan 2022 13:31:08 +0300 Subject: [PATCH] Add relaying to discord --- stdin2discord.py | 25 +++++++++++++++++++++++++ update_cec_list.bash | 1 + 2 files changed, 26 insertions(+) create mode 100644 stdin2discord.py diff --git a/stdin2discord.py b/stdin2discord.py new file mode 100644 index 0000000..fa9aa10 --- /dev/null +++ b/stdin2discord.py @@ -0,0 +1,25 @@ +import sys +import requests + +def send(_msg: str): + if len(_msg) == 0: + return + + r = requests.post( + url='https://discord.com/api/webhooks/936927833572380692/QrqoK8aVCOkGFh1L0HaHPd_Z-Usj-ubhXYvHadZyCA1Y5GOB7-0xWmuyKI9l4byvKjQ1', + data=f'content={requests.utils.quote(_msg)}'.encode('utf-8'), + headers = {'Content-Type': 'application/x-www-form-urlencoded'} + ) + r.raise_for_status() + +msg = '' + +for line in sys.stdin: + if len(msg + line) >= 2000: + send(msg) + msg = '' + + else: + msg += line + +send(msg) diff --git a/update_cec_list.bash b/update_cec_list.bash index 81ef801..ca97ad1 100755 --- a/update_cec_list.bash +++ b/update_cec_list.bash @@ -11,6 +11,7 @@ if [ $http_response != "200" ]; then else git diff "list.csv" + git diff "list.csv" | python3 stdin2discord.py git add "list.csv" git commit -m "commit" | grep -vE 'On branch master|nothing to commit, working tree clean' fi