Skip to content

Instantly share code, notes, and snippets.

@pgrandin
Created June 5, 2019 16:35
Show Gist options
  • Save pgrandin/ab222402cf519f8fc1e44a89cf891e2a to your computer and use it in GitHub Desktop.
Save pgrandin/ab222402cf519f8fc1e44a89cf891e2a to your computer and use it in GitHub Desktop.
import sys
import requests
from bs4 import BeautifulSoup
target=sys.argv[2]
cookies = {
'navitUserID': 'xxx',
'navitUserName': 'xxx',
'navitToken': 'xxx',
'navit_session': sys.argv[1],
}
headers = {
}
data = {
'wpTarget': target,
'wpExpiry': 'infinite',
'wpExpiry-other': '',
'wpReason': 'Spamming links to external sites',
'wpReason-other': '',
'wpCreateAccount': '1',
'wpDisableEmail': '1',
'wpDisableUTEdit': '1',
'title': 'Automated block',
'redirectparams': '',
'wpConfirm': ''
}
# Get a token to block user
response = requests.get('https://wiki.navit-project.org/index.php/Special:Block/'+target, headers=headers, cookies=cookies)
print('https://wiki.navit-project.org/index.php/Special:Block/'+target)
soup = BeautifulSoup(response.content, 'html5lib')
token = soup.find('input', {'id': 'wpEditToken'}).get('value')
print(token);
data['wpEditToken'] = token
# Block the user
response = requests.post('https://wiki.navit-project.org/index.php/Special:Block/'+target, headers=headers, cookies=cookies, data=data)
# Get a token to get the list of pages created by user
response = requests.get('https://wiki.navit-project.org/index.php/Special:Nuke', headers=headers, cookies=cookies)
soup = BeautifulSoup(response.content, 'html5lib')
token = soup.find('input', {'name': 'wpEditToken'}).get('value')
print(token);
params = (
('title', 'Special:Nuke'),
('action', 'submit'),
)
data = {
'target': target,
'pattern': '',
'namespace': 'all',
'limit': '500',
'wpEditToken': token
}
# Get a list of pages created by user
response = requests.post('https://wiki.navit-project.org/index.php?title=Special:Nuke&action=submit', headers=headers, cookies=cookies, data=data)
soup = BeautifulSoup(response.content, 'html5lib')
token = soup.find('input', {'name': 'wpEditToken'}).get('value')
print(token);
params = (
('title', 'Special:Nuke'),
('action', 'delete'),
)
data = {
'wpReason': 'Mass deletion of pages added by ' + target,
'pages[]': 'User:' + target,
'wpEditToken': token
}
response = requests.post('https://wiki.navit-project.org/index.php?title=Special:Nuke&action=delete', headers=headers, cookies=cookies, data=data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment