テストサイトベタ書きを修正

This commit is contained in:
CyberRex
2025-08-28 10:49:03 +09:00
parent 83847e1413
commit 77230e78c0
3 changed files with 18 additions and 14 deletions

View File

@@ -5,11 +5,6 @@ import requests
import os import os
import argparse import argparse
class CFSite:
def __init__(self, url, plan):
self.url = url
self.plan = plan
parser = argparse.ArgumentParser(description='Check Cloudflare Edge Locations and post to Misskey.') parser = argparse.ArgumentParser(description='Check Cloudflare Edge Locations and post to Misskey.')
parser.add_argument('--dry-run', action='store_true', help='Run without posting to Misskey') parser.add_argument('--dry-run', action='store_true', help='Run without posting to Misskey')
args = parser.parse_args() args = parser.parse_args()
@@ -20,18 +15,13 @@ else:
print("config.py not found") print("config.py not found")
exit(1) exit(1)
test_sites = [
CFSite('misskey.io', 'Enterprise'),
CFSite('misskey.systems', 'Pro'),
CFSite('ohtrmi.cbrx.io', 'Free'),
]
result_txt = [] result_txt = []
result_txt.append('Cloudflare Edge Location Check') result_txt.append('Cloudflare Edge Location Check')
result_txt.append('') result_txt.append('')
# read from /cdn-cgi/trace # read from /cdn-cgi/trace
for site in test_sites: for site in config.test_sites:
planstr = f' ({site.plan})' if site.plan else ''
try: try:
response = requests.get(f"https://{site.url}/cdn-cgi/trace", timeout=5) response = requests.get(f"https://{site.url}/cdn-cgi/trace", timeout=5)
response.raise_for_status() response.raise_for_status()
@@ -40,9 +30,9 @@ for site in test_sites:
if colo_line: if colo_line:
colo = colo_line.split('=')[1] colo = colo_line.split('=')[1]
if colo in config.expected_edge_locations: if colo in config.expected_edge_locations:
result_txt.append(f'- {site.url} ({site.plan}) : {colo}✅️') result_txt.append(f'- {site.url}{planstr} : {colo}✅️')
else: else:
result_txt.append(f'- {site.url} ({site.plan}) : {colo}') result_txt.append(f'- {site.url}{planstr} : {colo}')
else: else:
print(f"Could not find 'colo' in the trace info for {site.url}") print(f"Could not find 'colo' in the trace info for {site.url}")
except requests.RequestException as e: except requests.RequestException as e:

4
classes.py Normal file
View File

@@ -0,0 +1,4 @@
class CFSite:
def __init__(self, url, plan = None):
self.url = url
self.plan = plan

View File

@@ -1,3 +1,5 @@
from classes import CFSite
# URL of Misskey instance # URL of Misskey instance
misskey_url = 'https://your-misskey-instance.com' misskey_url = 'https://your-misskey-instance.com'
@@ -5,6 +7,14 @@ misskey_url = 'https://your-misskey-instance.com'
# API token with notes:write permission is required # API token with notes:write permission is required
misskey_token = 'your-misskey-token' misskey_token = 'your-misskey-token'
# List of test sites
# If you don't want to display the plan, set plan to None
test_sites = [
CFSite(url = 'example1.com', plan = None),
CFSite(url = 'example2.com', plan = 'Pro'),
CFSite(url = 'example3.com', plan = 'Business'),
]
# Expected locations # Expected locations
# Default is 4 locations in Japan # Default is 4 locations in Japan
# For location codes you want to add, see https://www.feitsui.com/en/article/26 # For location codes you want to add, see https://www.feitsui.com/en/article/26