#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import sys
import os
import os.path
import json
import mwclient
import argparse
import time
import datetime
import pprint
import logging
logging.basicConfig(level=logging.WARNING)

parser = argparse.ArgumentParser(description="""Script for testing MediaWiki API""")
parser.add_argument("-config",help="""Path to a JSON file with configuration options!""")
parser.add_argument("-fileup",help="""File to be uploaded""")
args = parser.parse_args()

pp = pprint.PrettyPrinter(indent=4)

def main(argv):

	host = "localhost"
	user = None
	password = None
	protocol = "http"
	data = {}
	fileup = None

        
        if 'config' in args:
                with open(args.config) as json_data_file:
                        data = json.load(json_data_file)
        

	if args.fileup is not None:
		fileup = args.fileup

        if "mw" in data:
                if "host" in data["mw"]:
                        host = data["mw"]["host"]
                if "user" in data["mw"]:
                        user = data["mw"]["user"]
                if "password" in data["mw"]:
                        pwd = data["mw"]["password"]
                if "protocol" in data["mw"]:
                        protocol = data["mw"]["protocol"]
        
        site = mwclient.Site((protocol, host))
        
        if user and pwd :
                # Login parameters
                site.login(user, pwd)

        
        page = site.pages[u'Hacking']
        
        if page.can('edit') :

		page.save(u'My first hacking', summary=u'I did it', minor=False, bot=True )

		if page.exists :

			text = page.text()
			more = u'My little pony'

			text = text+more
			page.save( text, summary=u'I did it again', minor=False, bot=True )


	if fileup :
		site.upload(open( fileup ), 'myfile.jpg', 'My image')
		

if __name__ == "__main__":
	main(sys.argv[1:])

@@ -637,33 +637,17 @@
 = None%0A%0A
-        %0A        
+%09
 if 'conf
@@ -659,32 +659,18 @@
 n args:%0A
-                
+%09%09
 with ope
@@ -707,32 +707,11 @@
 le:%0A
-                        
+%09%09%09
 data
@@ -739,24 +739,16 @@
 a_file)%0A
-        
 %0A%0A%09if ar
@@ -794,24 +794,17 @@
 fileup%0A%0A
-        
+%09
 if %22mw%22 
@@ -812,32 +812,18 @@
 n data:%0A
-                
+%09%09
 if %22host
@@ -843,32 +843,11 @@
 %22%5D:%0A
-                        
+%09%09%09
 host
@@ -868,32 +868,18 @@
 %22host%22%5D%0A
-                
+%09%09
 if %22user
@@ -899,32 +899,11 @@
 %22%5D:%0A
-                        
+%09%09%09
 user
@@ -924,32 +924,18 @@
 %22user%22%5D%0A
-                
+%09%09
 if %22pass
@@ -959,32 +959,11 @@
 %22%5D:%0A
-                        
+%09%09%09
 pwd 
@@ -987,32 +987,18 @@
 sword%22%5D%0A
-                
+%09%09
 if %22prot
@@ -1022,32 +1022,11 @@
 %22%5D:%0A
-                        
+%09%09%09
 prot
@@ -1055,33 +1055,19 @@
 tocol%22%5D%0A
-        %0A        
+%09%0A%09
 site = m
@@ -1097,33 +1097,19 @@
  host))%0A
-        %0A        
+%09%0A%09
 if user 
@@ -1118,32 +1118,18 @@
 d pwd :%0A
-                
+%09%09
 # Login 
@@ -1143,24 +1143,10 @@
 ers%0A
-                
+%09%09
 site
@@ -1163,34 +1163,21 @@
 r, pwd)%0A
-%0A        %0A        
+%09%0A%09%0A%09
 page = s
@@ -1202,25 +1202,11 @@
 g'%5D%0A
-        %0A        
+%09%0A%09
 if p
@@ -1223,16 +1223,17 @@
 dit') :%0A
+%09
 %0A%09%09page.
@@ -1303,16 +1303,17 @@
 =True )%0A
+%09
 %0A%09%09if pa
@@ -1324,16 +1324,17 @@
 xists :%0A
+%09
 %0A%09%09%09text
@@ -1376,16 +1376,17 @@
 e pony'%0A
+%09
 %0A%09%09%09text
@@ -1469,17 +1469,19 @@
 =True )%0A
-%0A
+%09%0A%09
 %0A%09if fil
@@ -1542,18 +1542,16 @@
 image')%0A
-%09%09
 %0A%0Aif __n

fix indent