Page MenuHomePhabricator

Reassign mentees from inactives mentors in
Closed, ResolvedPublic


In some mentors are no more active and still receive on their talkpages questions from newcomers:

  1. user:عبد الله
  2. user:شيماء

It will be more efficient to reassign mentees from these two former mentors to active ones in this list.


Event Timeline

Doing this via a quick and simple Python script. I first fetched the list of mentors from the wiki page, and then all the mentees assigned to the unavailable mentors from the database. The script goes across all the mentees, picks a random new mentor, and assigns it via the API's setmentor functionality.

1#!/usr/bin/env python3
3import requests
4import random
5import time
7API_URL = ''
8USERNAME = 'Martin Urbanec (WMF)'
9PASSWORD = '' # password from Special:BotPasswords
10MENTORS = ["جار الله","محمد أحمد عبد الفتاح","صالح","أحمد ناجي","Dr-Taher","Avicenno","Glory20","فيصل","Nehaoua","بندر","فاطمة الزهراء","Dyolf77","Dr. Mohammed","سيف القوضي"]
11REASON = 'مرشدك السابق غير متوفر حاليا. قمنا بتعيين مرشد جديد لك!'
13s = requests.Session()
15 'User-Agent': 'Reassign mentors ('
18def make_request(payload):
19 payload['format'] = 'json'
20 return, data=payload)
22def get_token(type='csrf'):
23 r = make_request({
24 'action': 'query',
25 'meta': 'tokens',
26 'type': type
27 })
28 data = r.json()
29 return data.get('query', {}).get('tokens', {}).get('%stoken' % type)
31r = make_request({
32 "action": "login",
33 "lgname": USERNAME,
34 "lgpassword": PASSWORD,
35 "lgtoken": get_token('login')
39mentees = open('mentees.txt').read().split('\n')
40token = get_token()
42for mentee in mentees:
43 mentor = random.choice(MENTORS)
44 print("Setting %s's mentor to %s" % (mentee, mentor))
45 print(make_request({
46 "action": "growthsetmentor",
47 "mentee": mentee,
48 "mentor": mentor,
49 "reason": REASON,
50 "token": token
51 }).json())

Note the script requires local sysop privileges, and the runner should probably be in the bot group as well, to avoid flooding recent changes (the first mentor I'm reassigning has more than 4k of mentees).

We definitely should have a long term solution for this issue (T272376). For now, this is a suitable workaround I would say. Short to medium term (until communities can see the list of mentees assigned to people), it should be easy to convert the API-based script into a maintenance script.

The script just finished. 11k mentees for one mentor, over 4k for the other mentor.