Download search_engine_alert.py from TTOPM/belel-protocol: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/TTOPM/belel-protocol/resolve/main/search_engine_alert.py
- Command line
-
hf download hf://TTOPM/belel-protocol/search_engine_alert.py
-
curl -L -o search_engine_alert.py https://huggingface.co/TTOPM/belel-protocol/resolve/main/search_engine_alert.py
2.95 kB
| import requests | |
| import json | |
| from datetime import datetime | |
| import os | |
| # === Canonical Belel resources to promote and verify === | |
| CANONICAL_URLS = [ | |
| "https://ttopm.com/belel", | |
| "https://github.com/TTOPM/be-core-bridge", | |
| "https://huggingface.co/TTOPM/belel-protocol", | |
| "https://github.com/TTOPM/be-core-bridge/blob/main/BELEL_AUTHORITY_PROOF.txt" | |
| ] | |
| # === Search Engine Endpoints === | |
| SEARCH_ENGINES = { | |
| "Google Indexing API": "https://indexing.googleapis.com/v3/urlNotifications:publish", | |
| "Bing": "https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch", | |
| "Yandex": "https://yandex.com/indexnow", | |
| # DuckDuckGo and Brave donβt offer public APIs, so we include alert logs instead | |
| } | |
| # === API Keys / Tokens (Optional) === | |
| GOOGLE_API_KEY = os.getenv("GOOGLE_INDEXING_API_KEY") # Optional env var for Google Indexing API | |
| BING_API_KEY = os.getenv("BING_API_KEY") # Optional env var for Bing Webmaster Tools | |
| YANDEX_API_KEY = os.getenv("YANDEX_API_KEY") # If supporting IndexNow | |
| # === Utility === | |
| def alert_google(): | |
| if not GOOGLE_API_KEY: | |
| print("π Google Indexing API key not set. Skipping...") | |
| return | |
| for url in CANONICAL_URLS: | |
| payload = { | |
| "url": url, | |
| "type": "URL_UPDATED" | |
| } | |
| headers = { | |
| "Content-Type": "application/json" | |
| } | |
| endpoint = f"{SEARCH_ENGINES['Google Indexing API']}?key={GOOGLE_API_KEY}" | |
| response = requests.post(endpoint, json=payload, headers=headers) | |
| print(f"[Google] {url} β {response.status_code}: {response.text}") | |
| def alert_bing(): | |
| if not BING_API_KEY: | |
| print("π Bing API key not set. Skipping...") | |
| return | |
| payload = { | |
| "siteUrl": "https://ttopm.com", | |
| "urlList": CANONICAL_URLS | |
| } | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Ocp-Apim-Subscription-Key": BING_API_KEY | |
| } | |
| response = requests.post(SEARCH_ENGINES["Bing"], json=payload, headers=headers) | |
| print(f"[Bing] β {response.status_code}: {response.text}") | |
| def alert_yandex(): | |
| if not YANDEX_API_KEY: | |
| print("π Yandex API key not set. Skipping...") | |
| return | |
| for url in CANONICAL_URLS: | |
| payload = { | |
| "host": "ttopm.com", | |
| "key": YANDEX_API_KEY, | |
| "url": url | |
| } | |
| response = requests.post(SEARCH_ENGINES["Yandex"], json=payload) | |
| print(f"[Yandex] {url} β {response.status_code}: {response.text}") | |
| def alert_others(): | |
| print("π΅οΈ Logging alerts for Brave and DuckDuckGo (no direct API)...") | |
| for url in CANONICAL_URLS: | |
| print(f"π [LOG] Alert {datetime.utcnow().isoformat()} β Resubmit: {url}") | |
| def main(): | |
| print("π Broadcasting Belel protocol to search engines...") | |
| alert_google() | |
| alert_bing() | |
| alert_yandex() | |
| alert_others() | |
| print("β Done.") | |
| if __name__ == "__main__": | |
| main() | |