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 = {}
logaction_types_june = {}
logaction_types_july = {}
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
    for ev in s.logevents(user=userName, start='20160601000000', end='20160630235959', reverse=True):
        logaction_types_june[ev.type()]  = logaction_types_june.get(ev.type(), 0) + 1   
    for ev in s.logevents(user=userName, start='20160701000000', end='20160731235959', reverse=True):
        logaction_types_july[ev.type()]  = logaction_types_july.get(ev.type(), 0) + 1
    
    #print("New Log Genrated")
    return
        
#logaction_types
#logaction_types_apr
fo = open("latest.txt", "a")
def generateTemplate(logaction_types, logaction_types_apr , logaction_types_may , logaction_types_june, logaction_types_july):
    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'))+":"+str(logaction_types_june.get('gblblock','0'))+":"+str(logaction_types_july.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') )+":"+str(logaction_types_june.get('gblrename','0') )+":"+str(logaction_types_july.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') )+":"+str(logaction_types_june.get('gblrights','0') )+":"+str(logaction_types_july.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') )+":"+str(logaction_types_june.get('globalauth','0') )+":"+str(logaction_types_july.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'))+":"+str(logaction_types_june.get('mwoauthconsumer','0'))+":"+str(logaction_types_july.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') )+":"+str(logaction_types_june.get('rights','0') )+":"+str(logaction_types_july.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 : June :July
}}""")
    fo.write("\n")
    return
              
              
#fo = open("july.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_june, logaction_types_july)
    logaction_types.clear();
    logaction_types_apr.clear();
    logaction_types_may.clear();
    logaction_types_june.clear();
    logaction_types_july.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)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/srv/paws/lib/python3.4/site-packages/pywikibot/logentries.py in _createFromData(self, logdata)
    445             logtype = logdata['type']
--> 446             return LogEntryFactory._getEntryClass(logtype)(logdata, self._site)
    447         except KeyError:

/srv/paws/lib/python3.4/site-packages/pywikibot/logentries.py in __init__(self, apidata, site)
    147         # See bug T19781
--> 148         pos = self.data['title'].find('#')
    149         self.isAutoblockRemoval = pos > 0

/srv/paws/lib/python3.4/site-packages/pywikibot/logentries.py in __missing__(self, key)
     36                         _logger)
---> 37         raise KeyError("Log entry (%s) has no '%s' key" % (self._type, key))
     38 

KeyError: "Log entry (block) has no 'title' key"

During handling of the above exception, another exception occurred:

Error                                     Traceback (most recent call last)
<ipython-input-5-6105d876e5bb> in <module>()
     79     fo.writelines( ("==[[User:"+stewardListNew.get('name')+"|"+stewardListNew.get('name')+"]]==\n"))
     80     userName=stewardListNew.get('name');
---> 81     getLogData(userName)
     82     generateTemplate(logaction_types, logaction_types_apr , logaction_types_may , logaction_types_june, logaction_types_july)
     83     logaction_types.clear();

<ipython-input-5-6105d876e5bb> in getLogData(userName)
     28     from pywikibot import Site
     29     s = Site('meta', 'meta')
---> 30     for ev in s.logevents(user=userName, start='20160301000000', end='20160331235959', reverse=True):
     31         logaction_types[ev.type()]  = logaction_types.get(ev.type(), 0) + 1
     32 

/srv/paws/lib/python3.4/site-packages/pywikibot/data/api.py in __iter__(self)
   2789                     self.normalized = {}
   2790                 for item in resultdata:
-> 2791                     yield self.result(item)
   2792                     if isinstance(item, dict) and set(self.continuekey) & set(item.keys()):
   2793                         # if we need to count elements contained in items in

/srv/paws/lib/python3.4/site-packages/pywikibot/data/api.py in result(self, pagedata)
   3001     def result(self, pagedata):
   3002         """Instatiate LogEntry from data from api."""
-> 3003         return self.entryFactory.create(pagedata)
   3004 
   3005 

/srv/paws/lib/python3.4/site-packages/pywikibot/logentries.py in create(self, logdata)
    419         @return: LogEntry object representing logdata
    420         """
--> 421         return self._creator(logdata)
    422 
    423     @classmethod

/srv/paws/lib/python3.4/site-packages/pywikibot/logentries.py in _createFromData(self, logdata)
    448             pywikibot.debug('API log entry received:\n{0}'.format(logdata),
    449                             _logger)
--> 450             raise Error("Log entry has no 'type' key")

Error: Log entry has no 'type' key
from pywikibot import Site
s = Site('meta', 'meta')
s.logevents
help()
Welcome to Python 3.4's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.4/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> s.logevents
no Python documentation found for 's.logevents'

help> Site
no Python documentation found for 'Site'

help> ?!
no Python documentation found for '?!'

logaction_types
?!
 
 
 
 
 
 
 
 
 
 
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