Merge pull request #267 from RicterZ/dev

add counter
This commit is contained in:
Ricter Zheng 2023-02-06 17:51:54 +08:00 committed by GitHub
commit 179852a343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -17,9 +17,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: nhentai_test
steps: steps:
- name: Set env
run: |
echo "NHENTAI_COOKIE=csrftoken=zV4qotZJrHKTeEc9uEg5uvXV5qwTcZIHRjF3TgbkvP6OoxZNj8I6RFQeGSSiZT04; sessionid=t2x0ke3u5i1azg2kvepe7w0ej89btc7t; cf_chl_2=eff13178a8d7814; cf_clearance=Gti8UaeKBbXj2A7V0XFSGydeWbLj2VnqP83FnGx_wIU-1675675191-0-160" >> $GITHUB_ENV
echo "NHENTAI_UA=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" >> $GITHUB_ENV
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set up Python 3.10 - name: Set up Python 3.10
uses: actions/setup-python@v3 uses: actions/setup-python@v3

View File

@ -103,7 +103,7 @@ def favorites_parser(page=None):
return result return result
def doujinshi_parser(id_): def doujinshi_parser(id_, counter=0):
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()): if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):
raise Exception(f'Doujinshi id({id_}) is not valid') raise Exception(f'Doujinshi id({id_}) is not valid')
@ -112,7 +112,6 @@ def doujinshi_parser(id_):
doujinshi = dict() doujinshi = dict()
doujinshi['id'] = id_ doujinshi['id'] = id_
url = f'{constant.DETAIL_URL}/{id_}/' url = f'{constant.DETAIL_URL}/{id_}/'
counter = 0
try: try:
response = request('get', url) response = request('get', url)
@ -126,11 +125,11 @@ def doujinshi_parser(id_):
if counter == 10: if counter == 10:
logger.critical(f'Failed to fetch doujinshi information of id {id_}') logger.critical(f'Failed to fetch doujinshi information of id {id_}')
sys.exit(1) return None
logger.debug(f'Slow down and retry ({id_}) ...') logger.debug(f'Slow down and retry ({id_}) ...')
time.sleep(1) time.sleep(1)
return doujinshi_parser(str(id_)) return doujinshi_parser(str(id_), counter)
except Exception as e: except Exception as e:
logger.warning(f'Error: {e}, ignored') logger.warning(f'Error: {e}, ignored')