Compare commits
1 Commits
a5b334279d
...
b24f577734
Author | SHA1 | Date | |
---|---|---|---|
|
b24f577734 |
14
.gitea/workflows/update-list.yaml
Normal file
14
.gitea/workflows/update-list.yaml
Normal file
@ -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: DISCORD_WEBHOOK=${{ secrets.DISCORD_WEBHOOK }} bash update_cec_list.bash
|
30
stdin2discord.bash
Executable file
30
stdin2discord.bash
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
#!/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"
|
@ -1,31 +0,0 @@
|
|||||||
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'}
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
r.raise_for_status()
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
print(r.text)
|
|
||||||
raise
|
|
||||||
|
|
||||||
msg = ''
|
|
||||||
|
|
||||||
for line in sys.stdin:
|
|
||||||
if len(msg + line) >= 1900:
|
|
||||||
send(msg)
|
|
||||||
msg = ''
|
|
||||||
|
|
||||||
else:
|
|
||||||
msg += line
|
|
||||||
|
|
||||||
send(msg)
|
|
@ -1,28 +1,20 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
set -euo pipefail
|
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")
|
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
|
if [ $http_response != "200" ]; then
|
||||||
#echo "page not found"
|
#echo "page not found"
|
||||||
#cat list.csv
|
#cat list.csv
|
||||||
git reset --hard | grep -v "HEAD is now at"
|
git reset --hard
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
else
|
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"
|
||||||
git diff "list.csv" | python3 stdin2discord.py
|
git diff "list.csv" | bash stdin2discord.bash
|
||||||
git add "list.csv"
|
git add "list.csv"
|
||||||
git commit -m "commit"
|
git commit -m "commit"
|
||||||
git push
|
git push
|
||||||
fi
|
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'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user