Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 修复pushUrl未配置相关Secrets报错邮件 #1495

Merged
merged 14 commits into from
Sep 2, 2023
24 changes: 23 additions & 1 deletion .github/workflows/pushUrl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,26 @@ jobs:
run: pip install requests

- name: Push
run: python pushUrl.py --url ${{ secrets.URL }} --baidu_token ${{ secrets.BAIDU_TOKEN }} --bing_api_key ${{ secrets.BING_API_KEY }}
env:
URL: ${{ secrets.URL }}
BAIDU_TOKEN: ${{ secrets.BAIDU_TOKEN }}
BING_API_KEY: ${{ secrets.BING_API_KEY }}
run: |
if [ -n "$URL" ]; then
if [ -n "$BAIDU_TOKEN" ]; then
python pushUrl.py --url $URL --baidu_token $BAIDU_TOKEN
else
echo "请前往 Github Action Secrets 配置 BAIDU_TOKEN:"
echo "详情参见: 'https://www.ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9'"
fi
if [ -n "$BING_API_KEY" ]; then
python pushUrl.py --url $URL --bing_api_key $BING_API_KEY
else
echo "请前往 Github Action Secrets 配置 BING_API_KEY:"
echo "详情参见: 'https://www.ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9'"
fi
else
echo "请前往 Github Action Secrets 配置 URL:"
echo "详情参见: 'https://www.ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9'"
fi

13 changes: 3 additions & 10 deletions pushUrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

def parse_stiemap(site):
site = f'{site}/sitemap.xml'
print('解析站点地图中,请稍后……')
try:
result = requests.get(site)
big = re.findall('<loc>(.*?)</loc>', result.content.decode('utf-8'), re.S)
print('当前已有url:')
print(list(big))
return list(big)
except:
print('请检查你的url是否有误。')
Expand Down Expand Up @@ -70,7 +67,7 @@ def push_to_baidu(site, urls, token):

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='parse sitemap')
parser.add_argument('--url', type=str, help='The url of your website')
parser.add_argument('--url', type=str, default=None, help='The url of your website')
parser.add_argument('--bing_api_key', type=str, default=None, help='your bing api key')
parser.add_argument('--baidu_token', type=str, default=None, help='Your baidu push token')
args = parser.parse_args()
Expand All @@ -88,16 +85,12 @@ def push_to_baidu(site, urls, token):
urls = random.sample(urls, QUOTA)
# 推送bing
if args.bing_api_key:
print('正在推送至必应,请稍后……')
push_to_bing(args.url, urls, args.bing_api_key)
else:
print('未配置 Bing API Key')
print('详情参见: https://ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9')
# 推送百度
if args.baidu_token:
print('正在推送至百度,请稍后……')
push_to_baidu(args.url, urls, args.baidu_token)
else:
print('未配置 Baidu Token')
print('详情参见: https://ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9')
else:
print('请前往 Github Action Secrets 配置 URL')
print('详情参见: https://ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9')