From a13e7b075cebbf85b5bd9730ec7ca56f7a555fdb Mon Sep 17 00:00:00 2001 From: Ghlerrix Date: Mon, 7 Aug 2023 15:07:04 +0800 Subject: [PATCH] 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",