Page MenuHomePhabricator

Reassign mentees from inactives mentors in ar.wikipedia.org
Closed, ResolvedPublic

Description

In ar.wikipedia.org 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.

Thanks.

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
2
3import requests
4import random
5import time
6
7API_URL = 'https://ar.wikipedia.org/w/api.php'
8USERNAME = 'Martin Urbanec (WMF)'
9PASSWORD = '' # password from Special:BotPasswords
10MENTORS = ["جار الله","محمد أحمد عبد الفتاح","صالح","أحمد ناجي","Dr-Taher","Avicenno","Glory20","فيصل","Nehaoua","بندر","فاطمة الزهراء","Dyolf77","Dr. Mohammed","سيف القوضي"]
11REASON = 'مرشدك السابق غير متوفر حاليا. قمنا بتعيين مرشد جديد لك!'
12
13s = requests.Session()
14s.headers.update({
15 'User-Agent': 'Reassign mentors (murbanec-ctr@wikimedia.org)'
16})
17
18def make_request(payload):
19 payload['format'] = 'json'
20 return s.post(API_URL, data=payload)
21
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)
30
31r = make_request({
32 "action": "login",
33 "lgname": USERNAME,
34 "lgpassword": PASSWORD,
35 "lgtoken": get_token('login')
36})
37print(r.json())
38
39mentees = open('mentees.txt').read().split('\n')
40token = get_token()
41mentees.pop()
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.