feat: 增加创建脚本
This commit is contained in:
commit
4d0cad509e
105
gen_homepage.py
Normal file
105
gen_homepage.py
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Cloudflare API credentials
|
||||||
|
API_TOKEN = 'YOUR_API_TOKEN'
|
||||||
|
ZONE_ID = 'YOUR_ZONE_ID'
|
||||||
|
BASE_URL = f'https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/dns_records'
|
||||||
|
PATH = ''
|
||||||
|
# Headers for the API request
|
||||||
|
headers = {
|
||||||
|
'Authorization': f'Bearer {API_TOKEN}',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_dns_records(page=1):
|
||||||
|
params = {
|
||||||
|
'page': page,
|
||||||
|
'per_page': 100
|
||||||
|
}
|
||||||
|
response = requests.get(BASE_URL, headers=headers, params=params)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
def extract_a_and_cname_records(records):
|
||||||
|
filtered_records = [record for record in records if record['type'] in ['A', 'CNAME']]
|
||||||
|
return filtered_records
|
||||||
|
|
||||||
|
def get_record():
|
||||||
|
all_records = []
|
||||||
|
page = 1
|
||||||
|
while True:
|
||||||
|
result = get_dns_records(page)
|
||||||
|
all_records.extend(result['result'])
|
||||||
|
if result['result_info']['total_pages'] == page:
|
||||||
|
break
|
||||||
|
page += 1
|
||||||
|
|
||||||
|
a_and_cname_records = extract_a_and_cname_records(all_records)
|
||||||
|
|
||||||
|
with open(f'{PATH}/records.txt', 'w') as f:
|
||||||
|
for record in a_and_cname_records:
|
||||||
|
f.write(f"{record['name']}\n")
|
||||||
|
|
||||||
|
def read_domains(file_path):
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
domains = file.readlines()
|
||||||
|
return [domain.strip() for domain in domains]
|
||||||
|
|
||||||
|
def extract_subdomains(domain):
|
||||||
|
parts = domain.split('.')
|
||||||
|
if len(parts) > 2:
|
||||||
|
subdomain = '.'.join(parts[:-2])
|
||||||
|
else:
|
||||||
|
subdomain = parts[0]
|
||||||
|
return subdomain
|
||||||
|
|
||||||
|
def generate_html(domains):
|
||||||
|
domains.sort()
|
||||||
|
html_content = '''
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Domain Navigation</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; }
|
||||||
|
.container { display: flex; flex-wrap: wrap; }
|
||||||
|
.item { flex: 0 0 20%; box-sizing: border-box; padding: 0.5rem; }
|
||||||
|
.item a { display: block; padding: 1rem; background: #f3f3f3; border: 1px solid #ddd; text-align: center; border-radius: 0.25rem; transition: background 0.3s, transform 0.3s; }
|
||||||
|
.item a:hover { background: #e2e8f0; transform: scale(1.05); }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container mx-auto p-4">
|
||||||
|
<div class="container">
|
||||||
|
'''
|
||||||
|
for domain in domains:
|
||||||
|
subdomain = extract_subdomains(domain)
|
||||||
|
html_content += f'''
|
||||||
|
<div class="item">
|
||||||
|
<a href="https://{domain}">{subdomain}</a>
|
||||||
|
</div>
|
||||||
|
'''
|
||||||
|
html_content += '''
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
'''
|
||||||
|
return html_content
|
||||||
|
|
||||||
|
def write_html(html_content):
|
||||||
|
with open(f'{PATH}/index.html', 'w') as file:
|
||||||
|
file.write(html_content)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
get_record()
|
||||||
|
domains = read_domains(f'{PATH}/records.txt')
|
||||||
|
html_content = generate_html(domains)
|
||||||
|
write_html(html_content)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user