From 5690e32096be04f68a6f7445776735d9211cc6a0 Mon Sep 17 00:00:00 2001 From: tasi788 Date: Sat, 3 Sep 2022 14:00:16 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=94=B9=E7=94=A8=20netlify=20buil?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto_newversion.yml | 61 --------------------------- .github/workflows/gen_nofarm.yml | 36 ---------------- AutoBuild/builder.py | 55 ++++++++++++++++++++++++ domains.txt | 5 --- experimental.txt | 9 +--- filter.txt | 6 --- hosts.txt | 5 --- nofarm_hosts.txt | 2 +- 8 files changed, 57 insertions(+), 122 deletions(-) delete mode 100644 .github/workflows/auto_newversion.yml delete mode 100644 .github/workflows/gen_nofarm.yml create mode 100644 AutoBuild/builder.py diff --git a/.github/workflows/auto_newversion.yml b/.github/workflows/auto_newversion.yml deleted file mode 100644 index 8e07445..0000000 --- a/.github/workflows/auto_newversion.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Auto Update Version - -on: - push: - paths: - - "**.txt" - - "AutoBuild/pure_domain.py" - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.head_ref }} # Checkout the correct branch name - fetch-depth: 0 # Fetch the whole repo history - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - - name: Set up Git config - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - OLD_MSG=$(git log --format=%B -n1) - - - id: files - uses: jitterbit/get-changed-files@v1 - with: - format: "csv" - - - name: Run AutoUpdateVerNum - run: | - cd ${{ github.workspace }}/AutoBuild - mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.files.outputs.added_modified }}') - for added_modified_file in "${added_modified_files[@]}"; do - python auto_update_version.py ${added_modified_file} - done - - - name: Commit files modified by "AutoUpdateVerNum" step - run: | - git commit --amend -a -m "🤖 自動更新 版本號" -m"$OLD_MSG" || echo "[INFO] Fail to update version number, may not need to update at all?" - - - name: Run AutoBuild - run: | - cd ${{ github.workspace }}/AutoBuild - python pure_domain.py - - - name: Commit files modified by "AutoBuild" step - run: | - git commit --amend -a -m "🤖 自動更新 domains.txt" -m"$OLD_MSG" || echo "[INFO] Fail to commit domains.txt, may not need to update the file?" - - - name: Push changes - uses: ad-m/github-push-action@master - with: - force: true - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} diff --git a/.github/workflows/gen_nofarm.yml b/.github/workflows/gen_nofarm.yml deleted file mode 100644 index 066f9af..0000000 --- a/.github/workflows/gen_nofarm.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Hide_FarmContent_From_Search - -on: - workflow_dispatch: - push: - paths: - - "nofarm_hosts.txt" - - "AutoBuild/hide_farm.py" - -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - 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: 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 diff --git a/AutoBuild/builder.py b/AutoBuild/builder.py new file mode 100644 index 0000000..67f19ca --- /dev/null +++ b/AutoBuild/builder.py @@ -0,0 +1,55 @@ +import requests +import re +from datetime import datetime, timedelta, timezone + +filterlist = { + 'abp': ['experimental.txt', 'filter.txt'], + 'hosts': ['hosts.txt', 'nofarm_hosts.txt'] +} +url = 'https://filter.futa.gg/' +tz = timezone(timedelta(hours=+8)) +today = datetime.now(tz).date() + +class HEAD: + abp: str = '[Adblock Plus]\n' \ + '! Title: LowTechFilter {name}\n' \ + '! Version: {version}\n' \ + '! Expires: 1 hour\n' \ + '! Homepage: https://t.me/adguard_tw\n' \ + '! ----------------------------------------------------------------------\n' + hosts: str = '! FutaHosts\n' \ + '! LowTechFilter {name}\n' \ + '! URL: \n' \ + '! Version: {version}\n' \ + '! --------------------------------------------------\n' + + +for category in filterlist: + for filename in filterlist[category]: + r = requests.get(url+filename) + if r.status_code != 200: + break + pattern = r'(?<=Version: )(\d+\.\d+\.)(\d+)' + first = '\n'.join(r.text.splitlines()[:5]) + version = None + try: + version = re.findall(pattern, first, re.MULTILINE)[0] + except IndexError: + # https://www.ptt.cc/bbs/Battlegirlhs/M.1506615677.A.1A4.html + version = ('2017.0929.', '1') + + dt = datetime.strptime(version[0], '%Y.%m%d.').date() + newversion = today.strftime('%Y.%m%d.') + if dt != today: + newversion += '1' + else: + newversion += str(int(version[1]) + 1) + + with open(f'../{filename}', 'r') as files: + with open(f'../{filename}', 'w') as output: + heads: str = HEAD().__getattribute__(category) + news = heads.format( + name=filename.split('.')[0].replace('_', ' ').title(), + version=newversion + ) + output.write(news+files.read()) \ No newline at end of file diff --git a/domains.txt b/domains.txt index e629157..5bec5d8 100644 --- a/domains.txt +++ b/domains.txt @@ -1,8 +1,3 @@ -# FutaHosts -# LowTechFilter Host -# URL: -# Version: 2022.0902.1 -# -------------------------------------------------- 5hz.org awetd.club sexsa.xyz diff --git a/experimental.txt b/experimental.txt index dd1c6cc..e3a921e 100644 --- a/experimental.txt +++ b/experimental.txt @@ -1,11 +1,4 @@ -[Adblock Plus] -! Title: LowTechFilter Experimental -! Version: 2022.0728.01 -! Expires: 1 hour -! Homepage: https://t.me/adguard_tw -! ---------------------------------------------------------------------- -! -! === 此為實驗性過濾清單 === +! === 此為實驗性過濾清單 === ! === THIS IS AN EXPERIMENTAL FILTER === ! ! Shopee.tw diff --git a/filter.txt b/filter.txt index 0faa4eb..e4dc6e3 100644 --- a/filter.txt +++ b/filter.txt @@ -1,9 +1,3 @@ -[Adblock Plus] -! Title: LowTechFilter -! Version: 2022.0902.1 -! Expires: 1 hour -! Homepage: https://t.me/adguard_tw -! ---------------------------------------------------------------------- ! PTT 驗證 ! www.ptt.cc#%#document.onreadystatechange=()=>{if(location.pathname.includes('/ask/over18')){document.querySelectorAll('.over18-button-container>button[name="yes"]').forEach(x=>x.click())}}; ! ---------------------------------------------------------------------- diff --git a/hosts.txt b/hosts.txt index 7fdda86..c4d950a 100644 --- a/hosts.txt +++ b/hosts.txt @@ -1,8 +1,3 @@ -! FutaHosts -! LowTechFilter Host -! URL: -! Version: 2022.0902.1 -! -------------------------------------------------- ! 白清單 @@||ip2location.com^ @@||fonts.gstatic.com^ diff --git a/nofarm_hosts.txt b/nofarm_hosts.txt index c27a046..2396f44 100644 --- a/nofarm_hosts.txt +++ b/nofarm_hosts.txt @@ -1,7 +1,7 @@ ! LowTechHost ! LowTechFilter nofarm ! URL: -! 2021.0916.01 +! Version: 2021.0916.01 ! -------------------------------------------------- ||366service.com^ ||7box.vip^