diff --git a/.gitea/workflows/update-list.yaml b/.gitea/workflows/update-list.yaml new file mode 100644 index 0000000..b67b5fd --- /dev/null +++ b/.gitea/workflows/update-list.yaml @@ -0,0 +1,14 @@ +name: Push commit + +on: + push: + schedule: + - cron: "*/30 * * * *" + +jobs: + report: + runs-on: ubuntu-latest + steps: + - uses: https://github.com/ischanx/checkout@06c611454073903c9d44641d7e085b21115d3dcf + + - run: bash update_cec_list.bash \ No newline at end of file diff --git a/stdin2discord.bash b/stdin2discord.bash new file mode 100644 index 0000000..3c04fb1 --- /dev/null +++ b/stdin2discord.bash @@ -0,0 +1,27 @@ +#!/bin/bash +set -e + +send() { + local _msg=$1 + if [[ -z $_msg ]]; then + return + fi + + curl -X POST \ + -H "Content-Type: application/json" \ + -d "{\"content\":\"$_msg\"}" \ + "$DISCORD_WEBHOOK" +} + +msg="" + +while IFS= read -r line; do + if [[ ${#msg}${#line} -ge 2000 ]]; then + send "$msg" + msg="" + else + msg+="$line" + fi +done + +send "$msg" diff --git a/stdin2discord.py b/stdin2discord.py deleted file mode 100644 index 007eb5f..0000000 --- a/stdin2discord.py +++ /dev/null @@ -1,25 +0,0 @@ -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=```diff\n{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 d94b3eb..9ed2de8 100755 --- a/update_cec_list.bash +++ b/update_cec_list.bash @@ -1,27 +1,19 @@ #!/usr/bin/bash -cd ~/CEC_monitoring || { exit 1; echo "changing directory failed"; exit 1; } - http_response=$(curl -s -L -o list.csv -w "%{http_code}" "https://docs.google.com/spreadsheets/d/e/2PACX-1vTXE8HCavThmJt1Wshy3GyF2ZJ-264SbNRVucsPUe2rbEgpm-e3tqsX-8K2mwsG4ozBj6qUyOOd4RMe/pub?gid=1832580214&single=true&output=csv") if [ $http_response != "200" ]; then #echo "page not found" #cat list.csv - git reset --hard | grep -v "HEAD is now at" + git reset --hard exit 1 else + git config user.name 'user2' + git config user.email 'user2@localhost' + git remote set-url origin https://x-access-token:$GITHUB_TOKEN@gitea.demb.uk/$GITHUB_REPOSITORY git diff "list.csv" - git diff "list.csv" | python3 stdin2discord.py + git diff "list.csv" | bash stdin2discord.bash git add "list.csv" - git commit -m "commit" 2>/dev/null >/dev/null - git push 2>/dev/null + git commit -m "commit" + git push fi - -#curl -L -o "list.csv" -s "https://docs.google.com/spreadsheets/d/e/2PACX-1vTXE8HCavThmJt1Wshy3GyF2ZJ-264SbNRVucsPUe2rbEgpm-e3tqsX-8K2mwsG4ozBj6qUyOOd4RMe/pub?gid=1832580214&single=true&output=csv" || { echo "downloading failed"; exit 1; } - -#git diff "list.csv" -#git add "list.csv" -#git commit -m "commit" | grep -vE 'On branch master|nothing to commit, working tree clean' - - -