#!/usr/bin/env python3 # This file is a part of speedtest # Created at 01/17/2025 import os import sys core = getattr(sys.modules["__main__"], "__file__", None) if core: core = os.path.abspath(core) root = os.path.dirname(core) if root: os.chdir(root) import requests URLS_FILE = "urls.txt" SEARCH_STRINGS = ["azurespeed.com", "windows.net", "azure"] BASE_URL = "https://www.azurespeed.com/api/sas?regionName={location}&blobName=100MB.bin&operation=download" LOCATIONS = ("australiacentral", "australiaeast", "australiasoutheast", "centralindia", "eastasia", "japaneast", "japanwest", "koreacentral", "koreasouth", "newzealandnorth", "southindia", "southeastasia", "westindia") DIRECTIONS = ("southeast", "west", "south", "central", "east", "north") def convert_location(location: str) -> str: for direction in DIRECTIONS: if direction in location: location = location.replace(direction, "") location = direction.capitalize() + " " + location.capitalize() break return location def get_urls() -> list[tuple[str]]: new_urls = [] for location in LOCATIONS: url = BASE_URL.format(location=location) try: json = requests.get(url).json() new_url = json["url"] except Exception: continue new_urls.append((location, new_url)) return new_urls def rewrite_urls(new_urls: list[tuple[str]]): contents = [] with open(URLS_FILE, "r") as file: for line in file.read().splitlines(): line = line.strip() for str_ in SEARCH_STRINGS: if str_.lower() in line.lower(): break else: contents.append(line) with open(URLS_FILE, "w") as file: for (location, new_url) in new_urls: location = convert_location(location) file.write("{location}|Azure|{new_url}\n".format(location=location, new_url=new_url)) for item in contents: file.write(item + "\n") def update_azure_lists(): urls = get_urls() rewrite_urls(urls) def main(): update_azure_lists() if __name__ == "__main__": main()