diff --git a/.github/workflows/gen_nofarm.yml b/.github/workflows/gen_nofarm.yml index 2310cfd..6d3382e 100644 --- a/.github/workflows/gen_nofarm.yml +++ b/.github/workflows/gen_nofarm.yml @@ -2,7 +2,7 @@ name: Hide_FarmContent_From_Search on: push: - branches: [ master ] + branches: [master] jobs: # This workflow contains a single job called "build" @@ -11,25 +11,25 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" - - name: Run AutoBuild - run: | - cd AutoBuild - python hide_farm.py + - name: Run AutoBuild + run: | + cd AutoBuild + python hide_farm.py - - name: Commit files - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add hide_farm_from_search.txt - git commit -m "AutoBuild" - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.FUTAFILTERAUTOBUILD }} + - name: Commit files + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add hide_farm_from_search.txt + git commit -m "🤖 自動更新 NoFarm" + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.FUTAFILTERAUTOBUILD }} diff --git a/AutoBuild/hide_farm.py b/AutoBuild/hide_farm.py index c63930b..956f2d8 100644 --- a/AutoBuild/hide_farm.py +++ b/AutoBuild/hide_farm.py @@ -1,3 +1,8 @@ +import os +from datetime import datetime, timedelta, timezone + +tz = timezone(timedelta(hours=+8)) + domain_list = '' with open('../nofarm_hosts.txt', 'r') as files: for domains in files.read().split('\n'): @@ -7,5 +12,32 @@ with open('../nofarm_hosts.txt', 'r') as files: domain=domain ) +if not os.path.exists('../hide_farm_from_search.txt'): + with open('../hide_farm_from_search.txt', 'w') as files: + pass + +with open('../hide_farm_from_search.txt', 'r') as orig: + version, ver_dt = '', '' + try: + version = orig.read().split('\n')[2].split(': ')[1] + ver_dt = datetime.strptime(version[:-3], '%Y.%m%d').date() + except IndexError: + pass + + now = datetime.now(tz) + v = now.strftime('%Y.%m%d.') + if now.date() != ver_dt: + v += '01' + else: + v += str(int(version[-2:])+1).zfill(2) + with open('../hide_farm_from_search.txt', 'w') as files: - files.write(domain_list) + head = '[Adblock Plus]\n' \ + '! Title: Make futa great again!\n' \ + '! Version: {version}\n' \ + '! Expires: 1 hour\n' \ + '! Homepage: https://t.me/adguard_tw\n' \ + '! ----------------------------------------------------------------------\n'.format( + version=v + ) + files.write(head + domain_list)