quicktools / scripts /google_indexing.py
github-actions[bot]
deploy: sync to hugging face
4cb7ab8
import json
import requests
from google.oauth2 import service_account
from google.auth.transport.requests import Request
# Configuration
KEY_FILE = 'indexing_key.json'
URLS = [
"https://quicktools.dpdns.org/",
"https://quicktools.dpdns.org/en",
"https://quicktools.dpdns.org/de",
"https://quicktools.dpdns.org/es",
"https://quicktools.dpdns.org/fr",
"https://quicktools.dpdns.org/ru",
"https://quicktools.dpdns.org/ja",
"https://quicktools.dpdns.org/ko",
"https://quicktools.dpdns.org/visa-photo",
"https://quicktools.dpdns.org/en/visa-photo",
"https://quicktools.dpdns.org/de/visa-photo",
"https://quicktools.dpdns.org/es/visa-photo",
"https://quicktools.dpdns.org/fr/visa-photo",
"https://quicktools.dpdns.org/ru/visa-photo",
"https://quicktools.dpdns.org/ja/visa-photo",
"https://quicktools.dpdns.org/ko/visa-photo"
]
def get_access_token():
scopes = ['https://www.googleapis.com/auth/indexing']
credentials = service_account.Credentials.from_service_account_file(KEY_FILE, scopes=scopes)
credentials.refresh(Request())
return credentials.token
def notify_indexing(url):
token = get_access_token()
endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish'
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {token}'
}
payload = {
'url': url,
'type': 'URL_UPDATED'
}
response = requests.post(endpoint, headers=headers, json=payload)
return response.status_code, response.json()
if __name__ == '__main__':
print(f"๐Ÿš€ Starting indexing notification for {len(URLS)} URLs...")
for url in URLS:
status, result = notify_indexing(url)
if status == 200:
print(f"โœ… Success: {url}")
else:
print(f"โŒ Failed: {url} | Status: {status} | Error: {result}")