FANDOM


#!/usr/bin/python
# -*- coding: utf-8 -*-
 
__author__ = '[[User:Jr Mime]], based off of [[User:TyA]]'
__version__ = '1.0'
 
print """Welcome to the semi delete and protector from files!
 
This programs lets you delete and protect pages from a file!
"""
 
from simplemediawiki import MediaWiki
import getpass
import sys
 
 
def getUserName():
 
    username = raw_input('Username: ')  # Gets user's username
    return username
 
 
def getUserPass():
 
    password = getpass.getpass()  # Gets user's password
    return password
 
 
def deletePage(page):
 
    # Query string
 
    query = {
        'title': page,
        'reason': 'Bot - deleting non-question material that has escaped the filter',
        'format': 'json',
        'action': 'delete',
        'token': token,
        }
    try:
 
        # Attempt query
 
        wiki.call(query)
    except:
 
        print 'Error'
 
 
def protectPage(page):
 
    # Query string
 
    query = {
        'title': page,
        'reason': 'Bot - protecting non-question material that has escaped the filter',
        'format': 'json',
        'action': 'protect',
        'protections': 'create=sysop',
        'token': token,
        }
 
    try:
 
        # Attempt query
 
        wiki.call(query)
    except:
 
        print 'Error'
 
 
def getToken():
 
    # The query to request an edit token
 
    query = {
        'action': 'query',
        'prop': 'info',
        'intoken': 'edit',
        'titles': 'Main Page',
        'format': 'json',
        }
 
    # Make query call
 
    q = wiki.call(query)['query']['pages']
 
    for i in q:
 
        # Trying
 
        try:
 
            wiki.token = q[i]['edittoken']
            return wiki.token
        except:
 
        # No edit privelege
 
            wiki.token = None
            print 'Failed to get delete token!'
            return False
 
 
def start():
    counter = 1
 
    while counter is 1:
 
        page = [line.strip() for line in open('thingything.txt')]
        deletePage(page)
        protectPage(page)
 
 
url = raw_input('Sitename: ')  # Gets the API.php url
url = 'http://' + url + '.wikia.com/api.php'
wiki = MediaWiki(url)
 
username = getUserName()
password = getUserPass()
 
print 'Attempting to Login to ' + url  # Prints where it's trying to login to
 
# Attempt login....
 
if wiki.login(username, password) is True:
 
    print 'Login successful!'  # If successful
else:
 
    print 'Login failed.'
 
    username = getUserName()
    password = getUserPass()
 
    if wiki.login(username, password) is True:
 
        print 'Login successful!'
        start()
    else:
 
        print 'Login failed. Terminating... '
        sys.exit()
 
token = getToken()
start()

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.