예제 #1
0
def main(S):
    uname = fileget("uname.txt")
    passwd = fileget("passwd.txt")
    root = fileget("root.txt")
    ppfix = fileget("pageprefix.txt")
    delay = fileget("delay.txt")
    if uname == False or passwd == False or ppfix == False:
        exit(3)
    if root == False:
        log.warning(
            "root.txt not found! Using \"https://zh.wikipedia.org/w/api.php\"."
        )
        root = "https://zh.wikipedia.org/w/api.php"
    if delay == False:
        log.warning("delay.txt not found! Using \"5\"")
        delay == 5
    else:
        delay = int(delay)
    mw.chroot(root)
    token = mw.token(S, "login")[0]
    status = mw.login(S, token, uname, passwd)
    del passwd
    if status[0] == True:
        log.info("Logged in!")
    else:
        log.error("Login Failed.")
        exit(2)
    uname = status[1]
    listpage = "User:"******"/settings/list"
    listcontent = mw.getpage(S, listpage)[0]
    blist = []
    for x in listcontent.splitlines():
        blist.insert(-1, remove_prefix(x, "*"))
    log.info("Account List: " + str(blist))
    from requests_html import HTMLSession
    HS = HTMLSession()
    for y in blist:
        try:
            log.info("Processing " + y)
            tdata = mw.token(S, "csrf")
            starttimestamp = tdata[1]
            basetimestamp = mw.getpage(S, ppfix + "/" + y)[1]
            token = tdata[0]
            r = HS.get("https://space.bilibili.com/" + y)
            r.html.render()
            fans = r.html.find(".space-fans")[0].text
            log.info(y + ": " + fans)
            EDIT = mw.edit(S, token, ppfix + "/" + y, fans, y, True,
                           basetimestamp, starttimestamp, False)
            if EDIT[0] == False:
                log.error("error while editing " + title + ": " + EDIT[1])
                log.error(EDIT[2])
            time.sleep(delay)
        except Exception as e:
            log.error("Error while processing " + y)
            log.error(str(e))
            pass
예제 #2
0
파일: main.py 프로젝트: Emojigit/wp_noref
def main():
    # mw.setdebug(True)
    uname = fileget("uname.txt")
    passwd = fileget("passwd.txt")
    root = fileget("root.txt")
    if uname == False or passwd == False or root == False:
        exit(3)
    delay = 0
    try:
        delay = int(fileget("delay.txt"))
        if delay == 0:
            raise FileNotFoundError
    except FileNotFoundError:
        log.warning("delay.txt not found! using 5 seconds as the delay.")
        delay = 5
    except ValueError:
        log.error("Invalid int in delay.txt!")
        exit(3)
    finally:
        log.info("got delay.txt with " + str(delay) + " seconds delay")
    mw.chroot(root)
    token = mw.token(S, "login")[0]
    status = mw.login(S, token, uname, passwd)
    del passwd
    if status[0] == True:
        log.info("Logged in!")
    else:
        log.error("Login Failed.")
        exit(2)
    try:
        if sys.argv[1] != None:
            title = sys.argv[1]
            log.info("Processing " + title)
            PageHandler(title)
            exit(0)
    except IndexError:
        pass
    while True:
        try:
            RAN = mw.random(S, 0)
            if RAN[0] == False:
                log.error("Error while getting random pages: " + RAN[1])
                log.error(RAN[2])
                raise CustomError
            title = RAN[2]
            log.info("Processing " + title)
            PageHandler(title)
            log.info("Finished process of " + title)
            raise CustomError
        except CustomError:
            try:
                time.sleep(delay)
                continue
            except KeyboardInterrupt:
                log.info("Ctrl-C pressed, exiting")
                exit(0)
        except KeyboardInterrupt:
            log.info("Ctrl-C pressed, exiting")
            exit(0)
예제 #3
0
def undo(se, title, id):
    tdata = mw.token(se, "csrf")
    token = tdata[0]
    minor = False
    summary = input("Please type your edit summary: ")
    while True:
        minput = input("Do you want to mark your edit a minor edit? (Y/N) ")
        if minput == "Y" or minput == "y":
            minor = True
            break
        elif minput == "N" or minput == "n":
            minor = False
            break
        else:
            print("Please enter `Y` or `N`.")
    mw.undo(se, token, title, id, False, minor, summary)
예제 #4
0
def edit(se, title):
    tdata = mw.token(se, "csrf")
    starttimestamp = tdata[1]
    token = tdata[0]
    pagedata = mw.getpage(se, title)
    pagecontent = pagedata[0]
    pageTS = pagedata[1]
    content = editor.editor(pagecontent)
    minor = False
    summary = input("Please type your edit summary: ")
    while True:
        minput = input("Do you want to mark your edit a minor edit? (Y/N) ")
        if minput == "Y" or minput == "y":
            minor = True
            break
        elif minput == "N" or minput == "n":
            minor = False
            break
        else:
            print("Please enter `Y` or `N`.")
    mw.edit(se, token, title, content, summary, False, pageTS, starttimestamp,
            minor)
예제 #5
0
파일: main.py 프로젝트: Emojigit/wp_noref
def PageHandler(title):
    tdata = mw.token(S, "csrf")
    starttimestamp = tdata[1]
    token = tdata[0]
    PAGE = mw.getpage(S, title)
    CONT = PAGE[0]
    TS = PAGE[1]
    if CONT == "":
        log.warning("Page " + title + "Have no content or not exist!")
        return False
    reflist = GetRefList(CONT)
    Templates = TemplateHandler(reflist, CONT.upper())
    if Templates == "":
        log.info("Page " + title + " have no templates. Skipping.")
        return False
    else:
        log.info("Editing " + title)
    EDIT = mw.prependedit(S, token, title, Templates, "Bot add templates",
                          True, TS, starttimestamp, False, True)
    if EDIT[0] == False:
        log.error("error while editing " + title + ": " + EDIT[1])
        log.error(EDIT[2])
        return False
    return True
예제 #6
0
def main():
    editor.create()
    mw.chroot(chroot.chroot())
    print("TextWikiEdit Plus By Cato Yiu")
    print("Copyright (c) 2020 Cato Yiu")
    print("This program is under GNU GPLv3 license.")
    print("To get a list of command, use the `help` command.")
    while True:
        try:
            cmddata = input("> ").split(' ', 1)
            try:
                cmd = cmddata[0]
            except IndexError:
                continue
            try:
                param = cmddata[1]
            except IndexError:
                param = ""
            if cmd == "botpasswd":
                if param == "":
                    print("Usage: botpasswd <Username>")
                    continue
                paramm = param.rstrip()
                token = mw.token(S, "login")[0]
                print("Logging in as " + paramm)
                passwd = getpass.getpass("Plase enter your password: "******"Logged in!")
                else:
                    print("Login Failed.")
            elif cmd == "view":
                if param == "":
                    print("Usage: view <Page title>")
                    continue
                pagedata = mw.getpage(S, param.rstrip())
                pagecontent = pagedata[0]
                editor.ro(pagecontent)
            elif cmd == "edit":
                if param == "":
                    print("Usage: edit <Page title>")
                    continue
                edit(S, param)
            elif cmd == "whoami":
                uinfo = mw.whoami(S)
                if uinfo["id"] == 0:
                    print("You are IP user, the IP is " + uinfo["name"])
                else:
                    print("You are " + uinfo["name"] + ", the user ID is " +
                          str(uinfo["id"]))
            elif cmd == "logout":
                logout(S)
            elif cmd == "exit":
                logout(S)
                print("Bye")
                editor.remove()
                exit(0)
            elif cmd == "help":
                print("""List of command:
* botpasswd <Username> : Login via botpasswd
* view <Title> : view article's Content
* edit <Title> : Edit an article
* whoami : know who are you
* logout : logout
* rev <Title> : Get page history
* rollback <Username> <title> : Rollback edit by Username in a page
* undo <ID> <title> : Undo edit with ID <ID> in page <title>
* random [NS ID] : Get random page title in [NS ID] or main namespace
* clear : clear the screen
* nsinfo : Get wiki's namespaces infomation
* wikiinfo : Get wiki's general infomations
* exinfo : Get wii's extensions infomation
* getimage <File name> <Local dir> : Download a remote image
* userinfo <Username> : get user info
* emailuser : Email a user
* debug <bool> : change debug setting
* exit : Exit TextWikiPlus""")
            elif cmd == "rev":
                if param == "":
                    print("Usage: rev <Page title>")
                    continue
                editor.ro(
                    rev.get(mw.revisions(S, param.rstrip()), param.rstrip()))
            elif cmd == "rollback":
                if param == "":
                    print("Usage: rollback <Username> <Title>")
                    continue
                PARAMSplit = param.split(' ', 1)
                try:
                    Uname = PARAMSplit[0]
                    Title = PARAMSplit[1].rstrip()
                except KeyError:
                    print("Usage: rollback <Image Name> <Path>")
                    continue
                token = mw.token(S, "rollback")[0]
                mw.rollback(S, token, Title, Uname)
            elif cmd == "undo":
                try:
                    if param == "":
                        raise ParamError
                    PARAMSplit = param.split(' ', 1)
                    try:
                        ID = PARAMSplit[0]
                        Title = PARAMSplit[1].rstrip()
                    except KeyError:
                        raise ParamError
                    try:
                        undo(S, Title, int(ID.rstrip()))
                    except ValueError:
                        raise ParamError
                except ParamError:
                    print("Usage: undo <ID> <Title>")
                    pass
            elif cmd == "random":
                ns = 0
                if param == "":
                    ns = 0
                else:
                    try:
                        ns = int(param.rstrip())
                    except ValueError:
                        print("Param must be None or int!")
                        continue
                mw.random(S, ns)
            elif cmd == "clear":
                print(chr(27) + "[2J")
            elif cmd == "nsinfo":
                mw.nsinfo(S)
            elif cmd == "wikiinfo":
                print(mw.wikiinfo(S))
            elif cmd == "exinfo":
                editor.ro(mw.exinfo(S))
            elif cmd == "getimage":
                try:
                    if param == "":
                        raise ParamError
                    PARAMSplit = param.split(' ', 1)
                    try:
                        iname = PARAMSplit[0].rstrip()
                        path = PARAMSplit[1].rstrip()
                    except KeyError:
                        raise ParamError
                    cont = mw.getimage(S, iname)
                    if cont == False:
                        continue
                    bsave.bsave(path, cont)
                except ParamError:
                    print("Usage: getimage <Image Name> <Path>")
                    pass
            elif cmd == "userinfo":
                if param == "":
                    print("Usage: Userinfo <Username>")
                    continue
                mw.userinfo(S, param.rstrip())
            elif cmd == "euser" or cmd == "emailuser":
                if param == "":
                    print("Usage: emailuser <Username>")
                    continue
                emailuser(S, param.rstrip())
            elif cmd == "debug":
                if param == "True" or param == "true" or param == "1":
                    mw.setdebug(True)
                elif param == "False" or param == "false" or param == "0":
                    mw.setdebug(False)
                else:
                    print("current debug state: " + str(mw.setdebug()))
            elif cmd == "uc" or cmd == "usercontribs":
                if param == "":
                    print("Usage: usercontribs <Username>")
                    continue
                editor.ro(
                    uc.get(mw.usercontribs(S, param.rstrip()), param.rstrip()))
            elif cmd == "":
                continue
            else:
                print(cmd + ": command not found")
        except KeyboardInterrupt:
            print()
            pass
        except SystemExit:
            raise
        except:
            print()
            print(
                "[ERROR] an error raised! You can report it at https://github.com/Emojigit/textwikiplus"
            )
            editor.remove()
            raise
예제 #7
0
def logout(se):
    token = mw.token(S, "csrf")[0]
    mw.logout(se, token)
예제 #8
0
def emailuser(se, uname):
    tdata = mw.token(se, "csrf")
    token = tdata[0]
    title = input("Email subject: ")
    content = editor.editor("")
    mw.emailuser(se, token, uname, title, content)
예제 #9
0
                text = text + "|" + str(row[x])
        except IndexError:
            print("Error in CSV file line "+str(count)+": Missing infomation")
            return False
        text = text + "}}"
        # merge_two_dicts(x, y)
        # 0,2,3
        title = row[0]+"_("+row[2]+row[3]+")"
        ret = merge_two_dicts(ret, {title:text})
        count = count + 1
    return ret

def run()
    uname = input("Please enter your bot username: "******"Please enter your bot password: "******"login")[0]
    lgstatus = mw.login(S,lgtoken,uname,passwd)
    if lgstatus == False
        print("error while login")
        exit(1)
    del passwd
    tmp = input("Please confirm `"+csvpath+"` have right content, then press enter to continue...")
    data = get_content()
    for title, content in data.items():
        time.sleep(5)
        etokenDATA = mw.token(S,"csrf")
        if etokenDATA == False:
            print("error while getting token to edit "+title)
            continue
        etoken = etokenDATA[0]
        mw.edit(S,etoken,title,content,"Auto creating [[WP:IOWA]] articles via [[https://zh.wikipedia.org/wiki/User:SickManWP/沙盒/9]]",True,True)