add IndexNow script
This commit is contained in:
35
indexnow
Executable file
35
indexnow
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
import requests
|
||||
import validators
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
urls = sys.argv[1:]
|
||||
else:
|
||||
urls = sys.stdin.read().splitlines()
|
||||
|
||||
for url in urls:
|
||||
if not validators.url(url):
|
||||
sys.exit(2)
|
||||
|
||||
if not urls:
|
||||
sys.exit(3)
|
||||
|
||||
host = "grapheneos.org"
|
||||
api_url = "https://api.indexnow.org/indexnow"
|
||||
|
||||
with open("indexnow-key.txt") as keyfile:
|
||||
key = keyfile.read().strip()
|
||||
|
||||
def submit(urls):
|
||||
data = {
|
||||
"host": host,
|
||||
"key": key,
|
||||
"urlList": urls
|
||||
}
|
||||
r = requests.post(api_url, json=data)
|
||||
print(r.status_code)
|
||||
|
||||
submit(urls)
|
||||
Reference in New Issue
Block a user