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.values())

    #stewardList = json.loads(response)

#print ( response['query']['allusers']['name'])

#ef getStewardList(stewardList):
#from pywikibot import Site
#s = Site('meta', 'meta')
#stewardList=s.allusers(start="a", group='steward')
#print (stewardList)
#return

logaction_types = {}
logaction_types_apr = {}
logaction_types_may = {}
def getLogData(userName):
    from pywikibot import Site
    s = Site('meta', 'meta')
    for ev in s.logevents(user=userName, start='20160301000000', end='20160331235959', reverse=True):
        logaction_types[ev.type()]  = logaction_types.get(ev.type(), 0) + 1
   
    for ev in s.logevents(user=userName, start='20160401000000', end='20160430235959', reverse=True):
        logaction_types_apr[ev.type()]  = logaction_types_apr.get(ev.type(), 0) + 1
        
    for ev in s.logevents(user=userName, start='20160501000000', end='20160531235959', reverse=True):
        logaction_types_may[ev.type()]  = logaction_types_may.get(ev.type(), 0) + 1
    #print("New Log Genrated")
    return
        
#logaction_types
#logaction_types_apr
fo = open("foo.txt", "a")
def generateTemplate(logaction_types, logaction_types_apr , logaction_types_may):
    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'))+":"+str(logaction_types_apr.get('gblblock','0'))+":"+str(logaction_types_may.get('gblblock','0'))+"\n"  )
    fo.writelines ( "| group 2 ="+str (logaction_types.get('gblrename','0'))+":"+str(logaction_types_apr.get('gblrename','0') )+":"+str(logaction_types_may.get('gblrename','0') )+"\n")
    fo.write ( "| group 3 ="+ str(logaction_types.get('gblrights','0'))+":"+str(logaction_types_apr.get('gblrights','0') )+":"+str(logaction_types_may.get('gblrights','0') )+"\n")
    fo.write ( "| group 4 ="+ str(logaction_types.get('globalauth','0'))+":"+str(logaction_types_apr.get('globalauth','0') )+":"+str(logaction_types_may.get('globalauth','0') )+"\n")
    fo.write ( "| group 5 ="+ str(logaction_types.get('mwoauthconsumer','0'))+":"+str(logaction_types_apr.get('mwoauthconsumer','0'))+":"+str(logaction_types_may.get('mwoauthconsumer','0'))+"\n")
    fo.write ( "| group 6 ="+ str(logaction_types.get('rights','0'))+":"+str(logaction_types_apr.get('rights','0') )+":"+str(logaction_types_may.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 : April : May
}}""")
    fo.write("\n")
    return
              
              
fo = open("may.txt", "a")



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');
    getLogData(userName)
    generateTemplate(logaction_types, logaction_types_apr , logaction_types_may)
    logaction_types.clear();
    logaction_types_apr.clear();
    logaction_types_may.clear();
fo.close()    



#getStewardList(stewardList)
#print ("==[[User:Savh|Savh]]==")
#getLogData(userName=stewardListNew.get('name'))
#generateTemplate(logaction_types, logaction_types_apr)
#print ("==[[User:Shanmugamp7|Shanmugamp7]]==")

#generateTemplate(logaction_types, logaction_types_apr)
import pywikibot
s = pywikibot.Site('ta', 'wikipedia')
#s.login(sysop=False)
page = pywikibot.Page(s, title='User:Shanmugamp7/Monthly Steward Statistics/By Steward1', ns=2)
text = page.text
page.text = u"newText"
page.save(u"bot test", force=True)

NoUsernameTraceback (most recent call last)
/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in _save(self, summary, watch, minor, botflag, async, callback, cc, quiet, **kwargs)
   1177             done = self.site.editpage(self, summary=summary, minor=minor,
-> 1178                                       watch=watch, bot=botflag, **kwargs)
   1179             if not done:

/srv/paws/lib/python3.4/site-packages/pywikibot/site.py in callee(self, *args, **kwargs)
   1299             if grp == 'user':
-> 1300                 self.login(False)
   1301             elif grp == 'sysop':

/srv/paws/lib/python3.4/site-packages/pywikibot/site.py in login(self, sysop)
   2051                                     'wrong': self.userinfo['name'],
-> 2052                                     'right': self._username[sysop]})
   2053             else:

NoUsername: Logged in on wikipedia:ta via OAuth as Shanmugamp7, but expect as None

During handling of the above exception, another exception occurred:

OtherPageSaveErrorTraceback (most recent call last)
<ipython-input-15-f700fe45fcd3> in <module>()
      5 text = page.text
      6 page.text = u"newText"
----> 7 page.save(u"bot test", force=True)

/srv/paws/lib/python3.4/site-packages/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1412                              cls, depth)
   1413                     del __kw[old_arg]
-> 1414             return obj(*__args, **__kw)
   1415 
   1416         if not __debug__:

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in save(self, summary, watch, minor, botflag, force, async, callback, apply_cosmetic_changes, quiet, **kwargs)
   1165             self._save(summary=summary, watch=watch, minor=minor,
   1166                        botflag=botflag, async=async, callback=callback,
-> 1167                        cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
   1168 
   1169     def _save(self, summary=None, watch=None, minor=True, botflag=None,

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in _save(self, summary, watch, minor, botflag, async, callback, cc, quiet, **kwargs)
   1191                 if isinstance(err, pywikibot.PageSaveRelatedError):
   1192                     raise err
-> 1193                 raise pywikibot.OtherPageSaveError(self, err)
   1194         if callback:
   1195             callback(self, err)

OtherPageSaveError: Edit to page [[wikipedia:ta:பயனர்:Shanmugamp7/Monthly Steward Statistics/By Steward1]] failed:
Logged in on wikipedia:ta via OAuth as Shanmugamp7, but expect as None
stewardList = {}
from pywikibot import Site
s = Site('meta', 'meta')
stewardList = s.allusers(group='steward', total=100)
print (stewardList.modules)
['allusers']
s.dbName

Collecting urllib
  Could not find a version that satisfies the requirement urllib (from versions: )
No matching distribution found for urllib
stewardList.resultkey

AttributeErrorTraceback (most recent call last)
<ipython-input-349-8360997b7954> in <module>()
----> 1 stewardList.resultkey

AttributeError: 'dict' object has no attribute 'resultkey'
stewardListNew.
            
{'name': 'Vituzzu', 'userid': 48915}
from pywikibot import Page
Page.
 
import urllib2
import json

response = urllib2.urlopen('https://api.instagram.com/v1/tags/pizza/media/XXXXXX')
data = json.load(response)   
print (data)

ImportErrorTraceback (most recent call last)
<ipython-input-382-ec7a366cf68a> in <module>()
----> 1 import urllib2
      2 import json
      3 
      4 response = urllib2.urlopen('https://api.instagram.com/v1/tags/pizza/media/XXXXXX')
      5 data = jsonload(response)

ImportError: No module named 'urllib2'
import json,urllib
fo = open("foo.txt", "a")

fo.write( ("==[[User:"+stewardListNew.get('name')+"|"+stewardListNew.get('name')+"]]=="))
fo.close()

%matplotlib inline
import seaborn as sns
sns.barplot(x=list(logaction_types.keys()), y=list(logaction_types.values()))
<matplotlib.axes._subplots.AxesSubplot at 0x7fa404ecb198>
logaction_types
{'gblblock': 3, 'globalauth': 12, 'suppress': 2}
!pip install seaborn
Collecting urllib2
  Could not find a version that satisfies the requirement urllib2 (from versions: )
No matching distribution found for urllib2