forked from felixonmars/dnsmasq-china-list
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Convert Conf Files | ||
|
||
on: | ||
schedule: | ||
- cron: "0 1 * * *" # every day | ||
workflow_dispatch: | ||
|
||
jobs: | ||
convert_conf_files: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: pip3 install glob2 | ||
|
||
- name: Convert Conf Files | ||
env: | ||
DNS_URL: ${{ secrets.DNS_URL }} | ||
run: python convert.py | ||
|
||
- name: Commit changes | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
current_time=$(date +'%Y-%m-%d %H:%M:%S') | ||
git add . | ||
git commit -m "Convert conf files to txt - $current_time" | ||
- name: Push changes | ||
uses: ad-m/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: master |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import glob | ||
|
||
def convert_conf_to_txt(conf_file, txt_file, dns_url): | ||
with open(conf_file, 'r') as conf: | ||
with open(txt_file, 'w') as txt: | ||
for line in conf: | ||
parts = line.strip().split('=') | ||
if len(parts) != 2: | ||
print(f"Invalid line: {line.strip()}") | ||
continue | ||
domain = parts[1].split('/')[1] | ||
txt.write(f"[/{domain}/]" + dns_url + "\n") | ||
|
||
def main(): | ||
current_directory = os.getcwd() # 获取当前目录 | ||
# 使用glob匹配以.conf结尾的文件 | ||
conf_files = glob.glob(os.path.join(current_directory, '*china.conf')) | ||
# 逐个读取文件内容 | ||
for thefile in conf_files: | ||
if os.path.basename(thefile) == 'bogus-nxdomain.china.conf': | ||
continue | ||
convert_conf_to_txt(thefile, thefile + ".txt", dns_url) | ||
|
||
# 从环境变量中获取 DNS URL | ||
dns_url = os.environ.get('DNS_URL') | ||
|
||
# 检查 DNS URL 是否为空 | ||
if dns_url is None: | ||
print("DNS_URL 环境变量未设置") | ||
else: | ||
main() |