From 71d5a29c6e87be567a5c774ee49ca1dc239db956 Mon Sep 17 00:00:00 2001 From: user2 Date: Thu, 11 Jul 2024 15:31:10 +0300 Subject: [PATCH] revert back to cron job --- .gitea/workflows/update-list.yaml | 14 -------------- stdin2discord.bash | 30 ------------------------------ stdin2discord.py | 26 ++++++++++++++++++++++++++ update_cec_list.bash | 18 +++++++++++++----- 4 files changed, 39 insertions(+), 49 deletions(-) delete mode 100644 .gitea/workflows/update-list.yaml delete mode 100755 stdin2discord.bash create mode 100644 stdin2discord.py diff --git a/.gitea/workflows/update-list.yaml b/.gitea/workflows/update-list.yaml deleted file mode 100644 index f793a3e..0000000 --- a/.gitea/workflows/update-list.yaml +++ /dev/null @@ -1,14 +0,0 @@ -name: Push commit - -on: - push: - schedule: - - cron: "30 * * * *" - -jobs: - report: - runs-on: ubuntu-latest - steps: - - uses: https://github.com/ischanx/checkout@06c611454073903c9d44641d7e085b21115d3dcf - - - run: DISCORD_WEBHOOK=${{ secrets.DISCORD_WEBHOOK }} bash update_cec_list.bash \ No newline at end of file diff --git a/stdin2discord.bash b/stdin2discord.bash deleted file mode 100755 index a5d55f8..0000000 --- a/stdin2discord.bash +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -set -euo pipefail -set -x - -send() { - local _msg=$1 - if [[ -z $_msg ]]; then - return - fi - - curl -X POST \ - -H "Content-Type: application/json" \ - -d "{\"content\":\"\`\`\`diff\n$_msg\`\`\`\"}" \ - "$DISCORD_WEBHOOK" -} - -msg="" - -while IFS= read -r line; do - line="$(sed 's@"@\\"@g' <<< "$line")" # Json screening - len="$(wc -m <<< "$msg$line")" - if [[ $len -ge 1985 ]]; then - send "$msg" - msg="$line" - else - msg+="$line\\n" - fi -done - -send "$msg" diff --git a/stdin2discord.py b/stdin2discord.py new file mode 100644 index 0000000..a55f99f --- /dev/null +++ b/stdin2discord.py @@ -0,0 +1,26 @@ +import sys +import requests +import os + +def send(_msg: str): + if len(_msg) == 0: + return + + r = requests.post( + url=os.environ['DISCORD_WEBHOOK'], + 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 4d447e0..63a1435 100755 --- a/update_cec_list.bash +++ b/update_cec_list.bash @@ -1,20 +1,28 @@ #!/usr/bin/bash set -euo pipefail +cd "$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" || { 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 + git reset --hard | grep -v "HEAD is now at" 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" | bash stdin2discord.bash + git diff "list.csv" | python3 stdin2discord.py git add "list.csv" 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' + + +