Utente:Ajeje Bot/blockspam.py

Da Vikidia, l'enciclopedia libera dagli 8 ai 13 anni
 1 #!/usr/bin/python3
 2 # -*- coding: utf-8 -*-
 3 
 4 import requests
 5 import login
 6 
 7 urlapi = "https://it.vikidia.org/w/api.php"
 8 s = login.login(urlapi)
 9 
10 # Get CSRF token
11 p2 = {
12     "action": "query",
13     "meta": "tokens",
14     "format": "json"
15 }
16 r = s.get(url=urlapi, params=p2, headers=login.headers)
17 d = r.json()
18 CSRF_TOKEN = d['query']['tokens']['csrftoken']
19 
20 # Iterate over
21 listAF = s.get(urlapi + '?action=query&list=abuselog&aflfilter=5&aflprop=ids|user|title&afllimit=10&format=json', headers=login.headers)
22 listAF = listAF.json()
23 for i in listAF['query']['abuselog']:
24     p3 = {
25         "action": "block",
26         "user": i['user'],
27         "expiry": "infinite",
28         "reason": "spambot",
29         "nocreate": "true",
30         "autoblock": "true",
31         "token": CSRF_TOKEN,
32         "format": "json"
33     }
34 
35     r = s.post(urlapi, data=p3, headers=login.headers)
36     print(r.json())