Page MenuHomePhabricator
Paste P14136

(An Untitled Masterwork)
ActivePublic

Authored by Urbanecm_WMF on Feb 2 2021, 8:38 PM.
Tags
None
Referenced Files
F34912070: raw-paste-data.txt
Jan 9 2022, 11:58 AM
F34912067: raw-paste-data.txt
Jan 9 2022, 11:57 AM
F34086221: raw-paste-data.txt
Feb 2 2021, 8:38 PM
Subscribers
None
#!/usr/bin/env python3
import requests
import random
import time
API_URL = 'https://ar.wikipedia.org/w/api.php'
USERNAME = 'Martin Urbanec (WMF)'
PASSWORD = '' # password from Special:BotPasswords
MENTORS = ["جار الله","محمد أحمد عبد الفتاح","صالح","أحمد ناجي","Dr-Taher","Avicenno","Glory20","فيصل","Nehaoua","بندر","فاطمة الزهراء","Dyolf77","Dr. Mohammed","سيف القوضي"]
REASON = 'مرشدك السابق غير متوفر حاليا. قمنا بتعيين مرشد جديد لك!'
s = requests.Session()
s.headers.update({
'User-Agent': 'Reassign mentors (murbanec-ctr@wikimedia.org)'
})
def make_request(payload):
payload['format'] = 'json'
return s.post(API_URL, data=payload)
def get_token(type='csrf'):
r = make_request({
'action': 'query',
'meta': 'tokens',
'type': type
})
data = r.json()
return data.get('query', {}).get('tokens', {}).get('%stoken' % type)
r = make_request({
"action": "login",
"lgname": USERNAME,
"lgpassword": PASSWORD,
"lgtoken": get_token('login')
})
print(r.json())
mentees = open('mentees.txt').read().split('\n')
token = get_token()
mentees.pop()
for mentee in mentees:
mentor = random.choice(MENTORS)
print("Setting %s's mentor to %s" % (mentee, mentor))
print(make_request({
"action": "growthsetmentor",
"mentee": mentee,
"mentor": mentor,
"reason": REASON,
"token": token
}).json())