Commit b2f45081 authored by cpettet's avatar cpettet
Browse files

getwikirights: quick and dirty script to show user rights onwiki(s)

Lots of room for improvement but want to share.

Change-Id: I02bf9f95ca63132de89e60958f28af4d40a1b565
parent be880c34
#!/usr/bin/python3
# Get global and per wiki rights for a user
try:
import requests
except ImportError:
print('Install requests3 library')
import getpass
import sys
import json
def main():
user = sys.argv[1]
req = 'https://meta.wikimedia.org/w/api.php?action=query&format=json&meta=globaluserinfo&guiuser={}&guiprop=groups%7Crights%7Cmerged'
req_user = req.format(user)
r = requests.get(req_user)
results = json.loads(r.content.decode('utf-8'))
if '-v' in sys.argv:
print(results)
else:
global_groups = ','.join(results['query']['globaluserinfo']['groups'])
print('global: {}'.format(global_groups))
wikis = results['query']['globaluserinfo']['merged']
wap = {}
for w in wikis:
if 'groups' in w:
wiki = w['wiki']
rights = ','.join(w['groups'])
print("{}: {}".format(wiki, rights))
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment