Created
March 11, 2023 00:06
-
-
Save peterc/c7c2f0169efc8194940592d92571e91f to your computer and use it in GitHub Desktop.
Get the IPs that MediaWiki / Wikipedia blocks programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
# Initialize variables | |
api_url = "https://meta.wikimedia.org/w/api.php" | |
params = { | |
"action": "query", | |
"format": "json", | |
"list": "globalblocks", | |
"bglimit": "500" | |
} | |
blocked_ips = [] | |
count = 0 | |
while True: | |
response = requests.get(api_url, params=params) | |
response_json = response.json() | |
globalblocks = response_json["query"]["globalblocks"] | |
for block in globalblocks: | |
blocked_ips.append(block["address"]) | |
print(block["address"]) | |
if "continue" not in response_json: | |
break | |
count += 1 | |
if count > 10: | |
break | |
params["bgstart"] = response_json["continue"]["bgstart"] | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment