Beispiel #1
0
def login(ev):
    global w
    un = boxUsername.get()
    sv = boxServer2.get()
    passwd = boxPassword.get()
    w = mw.Wiki("https://" + sv + "/w/api.php", USERAGENT)
    w.login(un, passwd)
    tkm.showinfo('Done', 'Login done')
async def category(msg):
    wp = mw.Wiki("https://ja.scratch-wiki.info/w/api.php")
    wp.login("T-taku@T-takumini", "pass")
    str1 = msg.message.content.replace("jsw:category ", "")
    for page in wp.category(str1).categorymembers():
        print(page.title)
        embed = discord.Embed(title="カテゴリ" + str1 + "に含まれる記事", description=" ", color=0xffa500)
        embed.add_field(name="ページ:", value=(page.title), inline=False)
        await bot.say(embed=embed)
Beispiel #3
0
import mw_api_client as mw
import keyboard  # using module keyboard
import re
import mwparserfromhell
import time
wp = mw.Wiki("https://en.scratch-wiki.info/w/api.php", "PyUserScript version 0.4.1")
username = input('Please write your username, then press enter\n')
password = input('Password?\n')
wp.clientlogin(username, password)
link = input('Write the page exactly that you want to invite\n')
invitesender = wp.page("User:Ahmetlii/PyUserScript/whitelist")
user = '******'
wikicode=mwparserfromhell.parse(invitesender)
item=wikicode.filter_templates(recursive=False)[0]
for template in wikicode.filter_templates():
     if template.name.matches("/item"):
          users = str(template.get(1).value)-username
          specificpage = str(template.get(2).value)
          lister = [user+users]
          for x in lister:
               listread = wp.page(x)
               contents = listread.read()
               contents += '\n==Discussion Invitation==\n{{subst:Discussion Invitation|'+link+'}}\nThis invitation sent by [[User:Ahmetlii/PyUserScript|PyUserScript]]. If you do not want to take invitations automatically, please contact with the [[User talk:'+username+'|'+username+']] for invitations or the [[User talk:Ahmetlii|programmer]] for errors.~~~~'
               summary = "Sent an invitation with [[User:Ahmetlii/PyUserScript|PyUserScript]]"
               listread.edit(contents, summary)
               print('An invitation sent by autoscript. It will close when all of them are sent.')
Beispiel #4
0
def get_wiki():
    wp = mw.Wiki("https://archonarcana.com/api.php", passwords.WIKI_BOT_NAME)
    wp.login(passwords.WIKI_BOT_LOGIN, passwords.WIKI_BOT_PASSWORD)
    return wp
Beispiel #5
0
"""Test exception handling"""
from unittest import TestCase
import mw_api_client as mw

WP = mw.Wiki('https://en.wikipedia.org/w/api.php')


class TestExcs(TestCase):
    """TestCase class to test exception handling."""
    def test_error(self):
        """Test general WikiError catching."""
        errored = False
        try:
            WP.page('Main Page').edit('unit test', 'unit test')
        except mw.WikiError:
            errored = True
        self.assertTrue(errored)

    def test_conflict(self):
        """Test catching an edit conflict."""
        sandbox1 = WP.page('Project:Sandbox')
        sandbox2 = WP.page('Project:Sandbox')
        content1 = sandbox1.read()
        try:
            sandbox2.edit(sandbox2.read() + 'testing conflict',
                          'testing edit conflict')
        except mw.WikiError.blocked:
            self.skipTest('This IP is blocked from editing')
            return
        errored = False
        try:
Beispiel #6
0
if __name__ == "__main__":
    import argparse
    import mw_api_client as mwc
    import bot
    from _secret import USERNAME, PASSWORD

    wiki = mwc.Wiki("https://ja.scratch-wiki.info/w/api.php", "Apple Bot")
    wiki.login(USERNAME, PASSWORD)
    my_bot = bot.Bot(wiki)
    running = []

    parser = argparse.ArgumentParser(description='Run the bot.')
    parser.add_argument('--disable',
                        nargs='*',
                        metavar='feature',
                        help='disable bot feature(s)')
    cmdargs = parser.parse_args()

    if 'news' not in cmdargs.disable:
        from news_update import NewsUpdateBot
        running.append(NewsUpdateBot)

    my_bot.run(*running)
import mw_api_client as mw
# Requires Kenny2github's code

jasw = mw.Wiki("https://ja.scratch-wiki.info/w/api.php",
               "GetPage by Apple502j via mw-api-client")
randoms = jasw.random(limit=50, namespace=0)
for page in randoms:
    with open("char-list.txt", "r", encoding="utf-8") as c:
        with open("lookedfor-wiki.txt", "a", encoding="utf-8") as n:
            chars = set()
            load_chars = set()
            for lchar in c.read():
                load_chars.add(lchar)
            for char in page.read():
                chars.add(char)
            unexist = chars - load_chars
            n.write("".join(map(str, list(unexist))))
            print("Checked page " + page.title)
Beispiel #8
0
"""Test various aspects of the Wiki."""
from sys import version_info
from unittest import TestCase
import mw_api_client as mw

if version_info[0] > 2:
    basestring = str # pylint: disable=invalid-name

# pylint: disable=protected-access
WP = mw.Wiki('https://en.wikipedia.org/w/api.php', 'Test suite')
class TestQyoo(TestCase):
    """Test the Wiki class."""
    def test_qyoo(self):
        """Assert that creating a Queue initializes it properly."""
        queue = mw.Queue(WP, (WP.page('Project:Sandbox'),
                              WP.page('Draft:Sandbox')))
        for i, thing in enumerate(queue._things):
            self.assertEqual(('Project:Sandbox', 'Draft:Sandbox')[i],
                             thing.title)
    def test_qyoo_fromtitles(self):
        """Assert fromtitles classmethod of Queue works properly."""
        queue = mw.Queue.fromtitles(WP, ('Project:Sandbox', 'Draft:Sandbox'))
        for i, thing in enumerate(queue._things):
            self.assertEqual(('Project:Sandbox', 'Draft:Sandbox')[i],
                             thing.title)
    def test_qyoo_frompages(self):
        """Assert frompages checks type."""
        try:
            mw.Queue.frompages(WP, (WP.page('Project:Sandbox'),
                                    'not a Page'))
            self.assertTrue(1 != 1)
Beispiel #9
0
def firstup(txt):
    arr = list(txt)
    arr[0] = arr[0].upper()
    return "".join(arr)


INTERWIKI = ['de', 'ja', 'nl', 'hu', 'id', 'ru',
             'fr']  # Do not include "get" and "set" wiki.
WIKI_GET = "https://en.scratch-wiki.info/w/api.php"  # Where the bot gets the info of interwiki
WIKI_SET = "https://test.scratch-wiki.info/w/api.php"  # Where the bot puts the interwiki

USERNAME = "******"  # Change it before using!
PASSWORD = getpass.getpass()  # Always asks

wGet = mwc.Wiki(
    WIKI_GET,
    "Apple_Bot (Only read!) v1.0 with python3/requests/mw-api-client")
wSet = mwc.Wiki(WIKI_SET, "Apple_Bot v1.0 with python3/requests/mw-api-client")
wSet.login(USERNAME, PASSWORD)

for page in wSet.category("Translate").categorymembers():
    contents = page.read()
    print("Working:" + page.title)
    try:
        tmp = parseMWT(contents.replace("\n", ""))
        if tmp["name"].lower() != "translate":
            continue
        english = wGet.page(tmp["data"]["En"]).read()
        for lang in INTERWIKI:
            exist = re.search("\[\[" + lang + ":.*\]\]", english)
            if exist: