From 770382afb54839eae033c1d26edeb47be4672966 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 14:51:20 +0800 Subject: [PATCH 01/14] test action and parse --- .github/workflows/baidupush.yml | 29 +++++++++++++++++++++++++++++ baidupush.py | 11 +++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .github/workflows/baidupush.yml create mode 100644 baidupush.py diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml new file mode 100644 index 00000000..7a13ab1f --- /dev/null +++ b/.github/workflows/baidupush.yml @@ -0,0 +1,29 @@ +## 利用GitHub Actions每天定时给百度推送链接,提高收录率 ## + +name: baiduPush + +# 两种触发方式:一、push代码,二、每天国际标准时间23点(北京时间+8即早上7点)运行 +on: + push: + # schedule: + # - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule + +on: + schedule: + - cron: '*/5 * * * *' # 每5分钟一次,测试用 + +jobs: + bot: + runs-on: ubuntu-latest # 运行环境为最新版的Ubuntu + steps: + - name: 'Checkout codes' # 步骤一,获取仓库代码 + uses: actions/checkout@v2 + # - name: 'Run baiduPush' # 步骤二,执行sh命令文件 + # run: npm install && npm run baiduPush # 运行目录是仓库根目录 + - name: Set up Python 3.8 + uses: actions/setup-python@v1 + with: + python-version: 3.8 + + - name: parse sitemap + run: python baidupush.py \ No newline at end of file diff --git a/baidupush.py b/baidupush.py new file mode 100644 index 00000000..8906bf21 --- /dev/null +++ b/baidupush.py @@ -0,0 +1,11 @@ +import re +import ssl +import requests +ssl._create_default_https_context = ssl._create_unverified_context +url = 'https://www.ghlerrix.cn/sitemap.xml' +result = requests.get(url) +big = re.findall('(.*?)', result.content.decode('utf-8'), re.S) +for i in big: + print(i) + # op_xml_txt = open('xml.txt', 'a') + # op_xml_txt.write('%s\n' % i) From 7a3e163f29e9307c4b7b4fecb9db102a731e721e Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 14:53:24 +0800 Subject: [PATCH 02/14] modify baidupush.yml --- .github/workflows/baidupush.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index 7a13ab1f..90a5f19a 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -8,7 +8,7 @@ on: # schedule: # - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule -on: +# on: schedule: - cron: '*/5 * * * *' # 每5分钟一次,测试用 From bf177751ba8d754ac59be9c6cac1d9139e1cbed1 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 14:56:15 +0800 Subject: [PATCH 03/14] install requests --- .github/workflows/baidupush.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index 90a5f19a..f763a972 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -25,5 +25,8 @@ jobs: with: python-version: 3.8 + - name: install requests + run: pip install requests + - name: parse sitemap run: python baidupush.py \ No newline at end of file From a13e7b075cebbf85b5bd9730ec7ca56f7a555fdb Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:07:04 +0800 Subject: [PATCH 04/14] add args --- .github/workflows/baidupush.yml | 2 +- baidupush.py | 23 +++++++++++++++-------- baidupush.sh | 16 ++++++++++++++++ package.json | 3 ++- 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 baidupush.sh diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index f763a972..322a6166 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -29,4 +29,4 @@ jobs: run: pip install requests - name: parse sitemap - run: python baidupush.py \ No newline at end of file + run: npm run baidupush \ No newline at end of file diff --git a/baidupush.py b/baidupush.py index 8906bf21..16b90978 100644 --- a/baidupush.py +++ b/baidupush.py @@ -1,11 +1,18 @@ import re import ssl import requests -ssl._create_default_https_context = ssl._create_unverified_context -url = 'https://www.ghlerrix.cn/sitemap.xml' -result = requests.get(url) -big = re.findall('(.*?)', result.content.decode('utf-8'), re.S) -for i in big: - print(i) - # op_xml_txt = open('xml.txt', 'a') - # op_xml_txt.write('%s\n' % i) +import argparse + + +if __name__ == '__main__': + ssl._create_default_https_context = ssl._create_unverified_context + parser = argparse.ArgumentParser(description='parse sitemap') + parser.add_argument('url', help='The url of your website') + args = parser.parse_args() + url = f'{args.url}/sitemap.xml' + result = requests.get(url) + big = re.findall('(.*?)', result.content.decode('utf-8'), re.S) + for i in big: + print(i) + # op_xml_txt = open('xml.txt', 'a') + # op_xml_txt.write('%s\n' % i) diff --git a/baidupush.sh b/baidupush.sh new file mode 100644 index 00000000..b9a88748 --- /dev/null +++ b/baidupush.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# 确保脚本抛出遇到的错误 +set -e + +# 检查是否传入了正确的参数 +if [ $# -lt 1 ]; then + echo "Please provide the your website as an argument." + exit 1 +fi + +# 百度链接推送 +python baidupush.py $1 +# curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://vuepress.ghlerrix.cn&token=oUldnU4HZvSTlh0e" + +rm -rf urls.txt # 删除文件 \ No newline at end of file diff --git a/package.json b/package.json index 1eddba68..f0be8f37 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "start": "next start", "post-build": "next-sitemap --config next-sitemap.config.js", "export": "next build && next-sitemap --config next-sitemap.config.js && next export", - "bundle-report": "ANALYZE=true yarn build" + "bundle-report": "ANALYZE=true yarn build", + "baidupush": "bash baiduPush.sh 'www.ghlerrix.cn'" }, "dependencies": { "@giscus/react": "^2.2.6", From 279443ef205e43a63f5e8d048388d94d995a11c2 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:08:03 +0800 Subject: [PATCH 05/14] modify package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0be8f37..2424dfac 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "post-build": "next-sitemap --config next-sitemap.config.js", "export": "next build && next-sitemap --config next-sitemap.config.js && next export", "bundle-report": "ANALYZE=true yarn build", - "baidupush": "bash baiduPush.sh 'www.ghlerrix.cn'" + "baidupush": "bash baidupush.sh 'www.ghlerrix.cn'" }, "dependencies": { "@giscus/react": "^2.2.6", From ffcec4f3a514005f38cfc6451ca8f4cc3cbb48ed Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:09:31 +0800 Subject: [PATCH 06/14] fix url --- baidupush.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baidupush.py b/baidupush.py index 16b90978..c03217b7 100644 --- a/baidupush.py +++ b/baidupush.py @@ -9,7 +9,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='parse sitemap') parser.add_argument('url', help='The url of your website') args = parser.parse_args() - url = f'{args.url}/sitemap.xml' + url = f'https://{args.url}/sitemap.xml' result = requests.get(url) big = re.findall('(.*?)', result.content.decode('utf-8'), re.S) for i in big: From b40b8af2018daa3bf51a87498ecee6adb553124c Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:12:49 +0800 Subject: [PATCH 07/14] test api push --- .github/workflows/baidupush.yml | 4 ++-- baidupush.py | 6 +++--- baidupush.sh | 10 ++-------- package.json | 2 +- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index 322a6166..08e3c048 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -9,8 +9,8 @@ on: # - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule # on: - schedule: - - cron: '*/5 * * * *' # 每5分钟一次,测试用 + # schedule: + # - cron: '*/5 * * * *' # 每5分钟一次,测试用 jobs: bot: diff --git a/baidupush.py b/baidupush.py index c03217b7..63c82ed7 100644 --- a/baidupush.py +++ b/baidupush.py @@ -13,6 +13,6 @@ if __name__ == '__main__': result = requests.get(url) big = re.findall('(.*?)', result.content.decode('utf-8'), re.S) for i in big: - print(i) - # op_xml_txt = open('xml.txt', 'a') - # op_xml_txt.write('%s\n' % i) + # print(i) + op_xml_txt = open('xml.txt', 'a') + op_xml_txt.write('%s\n' % i) diff --git a/baidupush.sh b/baidupush.sh index b9a88748..debdf0c7 100644 --- a/baidupush.sh +++ b/baidupush.sh @@ -3,14 +3,8 @@ # 确保脚本抛出遇到的错误 set -e -# 检查是否传入了正确的参数 -if [ $# -lt 1 ]; then - echo "Please provide the your website as an argument." - exit 1 -fi - # 百度链接推送 -python baidupush.py $1 -# curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://vuepress.ghlerrix.cn&token=oUldnU4HZvSTlh0e" +python baidupush.py 'www.ghlerrix.cn' +curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://www.ghlerrix.cn&token=oUldnU4HZvSTlh0e" rm -rf urls.txt # 删除文件 \ No newline at end of file diff --git a/package.json b/package.json index 2424dfac..7eabbfba 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "post-build": "next-sitemap --config next-sitemap.config.js", "export": "next build && next-sitemap --config next-sitemap.config.js && next export", "bundle-report": "ANALYZE=true yarn build", - "baidupush": "bash baidupush.sh 'www.ghlerrix.cn'" + "baidupush": "bash baidupush.sh" }, "dependencies": { "@giscus/react": "^2.2.6", From 3a1e0efe5fdc9d65a57aa3cf468e64fc6b8eb8c5 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:13:43 +0800 Subject: [PATCH 08/14] fix file name --- baidupush.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baidupush.py b/baidupush.py index 63c82ed7..9d0c0130 100644 --- a/baidupush.py +++ b/baidupush.py @@ -14,5 +14,5 @@ if __name__ == '__main__': big = re.findall('(.*?)', result.content.decode('utf-8'), re.S) for i in big: # print(i) - op_xml_txt = open('xml.txt', 'a') + op_xml_txt = open('urls.txt', 'a') op_xml_txt.write('%s\n' % i) From fb2eef35d9811ba9cf2e29eb36fc21c52bd5ba4f Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:27:47 +0800 Subject: [PATCH 09/14] modify baidupush.sh --- baidupush.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/baidupush.sh b/baidupush.sh index debdf0c7..7901c56a 100644 --- a/baidupush.sh +++ b/baidupush.sh @@ -3,8 +3,10 @@ # 确保脚本抛出遇到的错误 set -e -# 百度链接推送 +# 解析sitemap.xml, 记得换成你自己的域名,注意检查是否包含‘www’ python baidupush.py 'www.ghlerrix.cn' + +# 百度链接推送,换成自己的token和域名 curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://www.ghlerrix.cn&token=oUldnU4HZvSTlh0e" rm -rf urls.txt # 删除文件 \ No newline at end of file From 865905dac8568c7745a3e1ee536f0cf77db39edb Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:31:33 +0800 Subject: [PATCH 10/14] test schedule task --- .github/workflows/baidupush.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index 08e3c048..27c5f30a 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -8,9 +8,9 @@ on: # schedule: # - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule -# on: - # schedule: - # - cron: '*/5 * * * *' # 每5分钟一次,测试用 +on: + schedule: + - cron: '*/5 * * * *' # 每5分钟一次,测试用 jobs: bot: From d5a894b77cdfc6f6df7ab7339ab0692241ea21a6 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:32:03 +0800 Subject: [PATCH 11/14] modify --- .github/workflows/baidupush.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index 27c5f30a..322a6166 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -8,7 +8,7 @@ on: # schedule: # - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule -on: +# on: schedule: - cron: '*/5 * * * *' # 每5分钟一次,测试用 From c7b57078d9f558e9792b6fab041f883083138309 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 16:03:10 +0800 Subject: [PATCH 12/14] schedule --- .github/workflows/baidupush.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index 322a6166..c1497098 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -1,16 +1,16 @@ ## 利用GitHub Actions每天定时给百度推送链接,提高收录率 ## -name: baiduPush +name: baidupush # 两种触发方式:一、push代码,二、每天国际标准时间23点(北京时间+8即早上7点)运行 on: push: - # schedule: - # - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule + schedule: + - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule # on: - schedule: - - cron: '*/5 * * * *' # 每5分钟一次,测试用 + # schedule: + # - cron: '*/5 * * * *' # 每5分钟一次,测试用 jobs: bot: @@ -28,5 +28,5 @@ jobs: - name: install requests run: pip install requests - - name: parse sitemap + - name: baidupush run: npm run baidupush \ No newline at end of file From c2bc5764a234550dbf48fdc14c17858170ea8a61 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Wed, 9 Aug 2023 13:40:14 +0800 Subject: [PATCH 13/14] test workflow_dispatch --- .github/workflows/baidupush.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index c1497098..b1bebf0e 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -7,6 +7,13 @@ on: push: schedule: - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule + workflow_dispatch: + inputs: + unconditional-invoking: + description: 'baidupush unconditionally' + type: boolean + required: true + default: true # on: # schedule: From 86f97ea8c6e00a654ba98bcfc67b8aba69b88874 Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Wed, 9 Aug 2023 13:43:30 +0800 Subject: [PATCH 14/14] remove on push --- .github/workflows/baidupush.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/baidupush.yml b/.github/workflows/baidupush.yml index b1bebf0e..2541e38f 100644 --- a/.github/workflows/baidupush.yml +++ b/.github/workflows/baidupush.yml @@ -4,7 +4,7 @@ name: baidupush # 两种触发方式:一、push代码,二、每天国际标准时间23点(北京时间+8即早上7点)运行 on: - push: + # push: schedule: - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule workflow_dispatch: