forked from oracle/oci-grafana-metrics
-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_region_list.py
34 lines (26 loc) · 1.38 KB
/
generate_region_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import re
# Function to fetch and process regions
def fetch_and_process_regions(custom_regions=None):
# Step 1: Fetch the raw content of the file from the URL
url = "https://raw.githubusercontent.com/oracle/oci-typescript-sdk/refs/heads/master/lib/common/lib/region.ts"
response = requests.get(url)
file_content = response.text
# Step 2: Find all lines that contain 'Region.register'
matches = re.findall(r'Region\.register\("([^"]+)"', file_content)
# Step 3: Sort the matches and remove duplicates
unique_sorted_matches = sorted(set(matches))
# Step 4: Add custom regions (if provided)
if custom_regions:
unique_sorted_matches.extend(custom_regions)
unique_sorted_matches = sorted(set(unique_sorted_matches)) # Remove duplicates after adding custom regions
# Step 5: Format the result to mimic the output of the original command
regions = ', '.join([f"'{match}'" for match in unique_sorted_matches])
regions = f"export const regions = [{regions}]"
# Step 6: Write the result to the file 'regionlist.ts'
with open('./src/regionlist.ts', 'w') as file:
file.write(regions)
print("Result successfully written to './src/regionlist.ts'")
# Example usage with custom regions
custom_regions = ['ap-silverdale-1', 'ap-hobsonville-1'] # Define custom regions here
fetch_and_process_regions(custom_regions)