stewardList = {}
stewardListNew = {}
import requests
url = 'https://meta.wikimedia.org/w/api.php?action=query&format=json&prop=&list=allusers&augroup=steward&aulimit=100'
response = requests.get(url)
#print (response.text)
import json
stewardList = json.loads(response.text)

#print(stewardList)


from pywikibot import Site
s = Site('meta', 'meta')
print (s.logevents)

logaction_types={}
logaction_types_feb={}

def getLogData(userName):
    #print("came here")

    for ev in s.logevents(user=userName, start='20170101000000', end='20170131235959', reverse=True):
        logaction_types[ev.type()]  = logaction_types.get(ev.type(), 0) + 1
        #print(logaction_types.get('block'),'0')

fo = open("JAN2017.txt", "a")



def generateTemplate(logaction_types):
    fo.writelines("""{{ #invoke:Chart | bar chart
| height = 350
| width = 900
| stack= 1""")
    fo.write("\n")
    fo.writelines ( "| group 1 ="+ str(logaction_types.get('gblblock','0'))+"\n"  )
    fo.writelines ( "| group 2 ="+str (logaction_types.get('gblrename','0'))+"\n")
    fo.write ( "| group 3 ="+ str(logaction_types.get('gblrights','0'))+"\n")
    fo.write ( "| group 4 ="+ str(logaction_types.get('globalauth','0'))+"\n")
    fo.write ( "| group 5 ="+ str(logaction_types.get('mwoauthconsumer','0'))+"\n")
    fo.write ( "| group 6 ="+ str(logaction_types.get('rights','0'))+"\n")
    fo.write ( "| colors = #0749FB:#ff00ff:#53F848:#6600cc:#ff0000:#ffff00\n")
    string1 = "gblblock:gblrename:gblrights:globalauth:mwoauthconsumer:rights"
    fo.write("| group names = "+string1+"\n")
    fo.writelines ("""| units suffix = actions
| x legends = March
}}""")
    fo.write("\n")
    return

for name in stewardList['query']['allusers']:   
#    print (name)
    stewardListNew.update(name)
    #print (stewardListNew.get('name'))
    fo.writelines( ("==[[User:"+stewardListNew.get('name')+"|"+stewardListNew.get('name')+"]]==\n"))
    userName=stewardListNew.get('name');
    print (userName)
    try:
        getLogData(userName)
        print("got log data")
        generateTemplate(logaction_types)
        print("Generated template")
    except : 
        print ("Exception Occured:"+userName)
        pass
    logaction_types.clear();
  
   
fo.close()    
<bound method APISite.logevents of APISite("meta", "meta")>
Ajraddatz
got log data
Generated template
Avraham
got log data
Generated template
Barras
got log data
Generated template
Bennylin
got log data
Generated template
Bsadowski1
got log data
Generated template
DerHexer
got log data
Generated template
Einsbor
got log data
Generated template
Hoo man
got log data
Generated template
Jyothis
got log data
Generated template
Linedwell
got log data
Generated template
MBisanz
got log data
Generated template
MF-Warburg
got log data
Generated template
MarcoAurelio
got log data
Generated template
Mardetanha
got log data
Generated template
Masti
got log data
Generated template
Matanya
got log data
Generated template
Melos
got log data
Generated template
Mentifisto
got log data
Generated template
NahidSultan
got log data
Generated template
Pmlineditor
got log data
Generated template
QuiteUnusual
got log data
Generated template
RadiX
got log data
Generated template
Ruslik0
got log data
Generated template
Savh
got log data
Generated template
Shanmugamp7
got log data
Generated template
Stryn
got log data
Generated template
Tegel
got log data
Generated template
Teles
got log data
Generated template
Trijnstel
got log data
Generated template
Vituzzu
got log data
Generated template