MCPcopy Create free account
hub / github.com/sammchardy/python-binance / fetch_endpoints

Function fetch_endpoints

code-generator.py:78–132  ·  view source on GitHub ↗

Fetch endpoints from the provided Binance doc URLs, filtering duplicates.

()

Source from the content-addressed store, hash-verified

76
77
78def fetch_endpoints():
79 """Fetch endpoints from the provided Binance doc URLs, filtering duplicates."""
80 endpoints = set()
81 deprecated_endpoints = set()
82 for url in URLS:
83 print(f"Fetching {url}")
84 page = requests.get(url)
85 soup = BeautifulSoup(page.content, "html.parser")
86 all_code_blocks = soup.find_all("code")
87
88 for code in all_code_blocks:
89 code_text = code.get_text().strip()
90 parts = code_text.split(" ")
91
92 if len(parts) >= 2:
93 parts[0] = parts[0].strip()
94 parts[1] = parts[1].strip().split("?")[0]
95 # Basic check for lines that look like: GET /path or POST /path etc.
96 if (
97 len(parts) >= 2
98 and parts[0] in ["GET", "POST", "PUT", "DELETE"]
99 and parts[1] is not None
100 and parts[1] != ""
101 ):
102 method = parts[0]
103 endpoint = parts[1]
104 # Ensure endpoint starts with /
105 if not endpoint.startswith("/"):
106 endpoint = "/" + endpoint
107
108 # Check both deprecated prefixes and specific endpoints
109 if (
110 any(endpoint.startswith(prefix) for prefix in DEPRECATED_PREFIXES)
111 or (method, endpoint) in DEPRECATED_ENDPOINTS
112 ):
113 deprecated_endpoints.add((method, endpoint))
114 continue # Skip adding to main endpoints set
115
116 # Use a tuple of (method, endpoint) for uniqueness
117 endpoints.add((method, endpoint))
118 print(f"Found {len(deprecated_endpoints)} deprecated endpoints in the docs.")
119 print(f"Found {len(endpoints)} unique endpoints in the docs.")
120
121 # Filter endpoints that don't start with any known prefix
122 valid_endpoints = {
123 (method, endpoint)
124 for method, endpoint in endpoints
125 if any(endpoint.startswith(prefix) for prefix in PREFIX_MAP.keys())
126 }
127
128 filtered_count = len(endpoints) - len(valid_endpoints)
129 print(f"Filtered out {filtered_count} endpoints that don't match known prefixes")
130 print(f"Remaining endpoints: {len(valid_endpoints)}")
131
132 return valid_endpoints
133
134
135def get_request_function_and_path(

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…