️ 保護 endpoint

This commit is contained in:
踢低吸 2023-07-10 06:28:03 +00:00
parent 97b117d30f
commit f3fb7210da
2 changed files with 13 additions and 3 deletions

View File

@ -16,7 +16,9 @@ jobs:
cache: 'pip' # caching pip dependencies
- run: pip install -r AutoBuild/requirements.txt && python AutoBuild/tw_165.py
env:
tw165: ${{ vars.TW165 }}
tw165json: ${{ vars.TW165JSON }}
tw165csv: ${{ vars.TW165CSV }}
auth: ${{ secrets.AUTH }}
- name: push
uses: github-actions-x/commit@v2.9
with:

View File

@ -1,4 +1,5 @@
import requests
from requests.auth import HTTPBasicAuth
from json.decoder import JSONDecodeError
import logging
import os
@ -10,11 +11,18 @@ logger = logging.getLogger(__name__)
def main():
url = os.getenv('tw165', None)
auth = os.getenv('auth', None)
url = os.getenv('tw165json', None)
if not url:
logger.critical('URL NOT SET')
return
r = requests.get(url)
if not auth:
logger.critical('AUTH NOT SET')
return
user, passwd = auth.split(':')
basic = HTTPBasicAuth(user, passwd)
r = requests.get(url, auth=basic)
if r.status_code != 200:
logger.critical('Fetch Data Err')
return