Skip to content

Commit

Permalink
[fix] 修复未配置Action Secrets每日定时推送报错
Browse files Browse the repository at this point in the history
- URL配置异常捕获,若URL配置错误会给出提示信息
- 未配置相关信息处理方式
  - 未配置URL:则啥也不干
  - 未配置Bing API KEY:则不推送至Bing
  - 未配置Baidu Token:则不推送至百度
  • Loading branch information
Ghlerrix committed Aug 26, 2023
1 parent 4809335 commit eec1db0
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions pushUrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
def parse_stiemap(site):
site = f'{site}/sitemap.xml'
print('解析站点地图中,请稍后……')
result = requests.get(site)
big = re.findall('<loc>(.*?)</loc>', result.content.decode('utf-8'), re.S)
print('当前已有url:')
print(list(big))
return list(big)
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是否有误。')
print('正确的应是完整的域名,包含https://,且不包含‘sitemap.xml’, 如下所示:')
print('正确的示例: https://ghlcode.cn')
print('详情参见: https://ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9')



def push_to_bing(site, urls, api_key):
Expand Down Expand Up @@ -62,16 +69,17 @@ def push_to_baidu(site, urls, token):
args = parser.parse_args()
if args.url:
urls = parse_stiemap(args.url)
if args.bing_api_key:
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:
push_to_baidu(args.url, urls, args.baidu_token)
else:
print('未配置 Baidu Token')
print('详情参见: https://ghlcode.cn/fe032806-5362-4d82-b746-a0b26ce8b9d9')
if urls is not None:
if args.bing_api_key:
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:
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')

0 comments on commit eec1db0

Please sign in to comment.