Пример #1
0
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)
        if "Database parameters" not in present_groups:
            Database.set_argparser(argparser)

        argparser.add_argument(
            "--page-name",
            default="ArchWiki:Maintenance Team",
            help=
            "the page name on the wiki to fetch and update (default: %(default)s)"
        )
        argparser.add_argument(
            "--days",
            action="store",
            default=30,
            type=int,
            metavar="N",
            help="the time span in days (default: %(default)s)")
        argparser.add_argument(
            "--min-edits",
            action="store",
            default=10,
            type=int,
            metavar="N",
            help=
            "minimum number of edits for moving into the \"active\" table (default: %(default)s)"
        )
Пример #2
0
    def set_argparser(argparser):
        import ws.config

        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)

        output = argparser.add_argument_group(title="output mode")
        _g = output.add_mutually_exclusive_group()
        # TODO: maybe leave only the short option to forbid configurability in config file
        _g.add_argument("-s", "--save", action="store_true",
                help="try to save the page (requires being logged in)")
        _g.add_argument("-p", "--print", action="store_true",
                help="print the updated text in the standard output (this is the default output method)")

        group = argparser.add_argument_group(title="script parameters")
        group.add_argument("-a", "--anonymous", action="store_true",
                help="do not require logging in: queries may be limited to a lower rate")
        # TODO: maybe leave only the short option to forbid configurability in config file
        group.add_argument("-f", "--force", action="store_true",
                help="try to update the page even if it was last saved in the same UTC day")
        group.add_argument("--toc-languages", default="all", type=ws.config.argtype_comma_list_choices(["all"] + lang.get_internal_tags()),
                help="a comma-separated list of language tags whose ToC pages should be updated (default: %(default)s)")
        group.add_argument("--toc-page", default="Table of contents",
                help="the page name on the wiki to fetch and update (the language suffix "
                     "is added automatically as necessary) (default: %(default)s)")
        # TODO: no idea how to forbid setting this globally in the config...
        group.add_argument("--summary", default="automatic update",
                help="the edit summary to use when saving the page (default: %(default)s)")
Пример #3
0
    def set_argparser(argparser):
        import ws.config

        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)

        output = argparser.add_argument_group(title="output mode")
        _g = output.add_mutually_exclusive_group()
        # TODO: maybe leave only the short option to forbid configurability in config file
        _g.add_argument("-s", "--save", action="store_true",
                help="try to save the page (requires being logged in)")
        _g.add_argument("-p", "--print", action="store_true",
                help="print the updated text in the standard output (this is the default output method)")

        group = argparser.add_argument_group(title="script parameters")
        group.add_argument("-a", "--anonymous", action="store_true",
                help="do not require logging in: queries may be limited to a lower rate")
        # TODO: maybe leave only the short option to forbid configurability in config file
        group.add_argument("-f", "--force", action="store_true",
                help="try to update the page even if it was last saved in the same UTC day")
        group.add_argument("--toc-languages", default="en", type=ws.config.argtype_comma_list_choices(["all"] + lang.get_internal_tags()),
                help="a comma-separated list of language tags whose ToC pages should be updated (default: %(default)s)")
        group.add_argument("--toc-page", default="目次",
                help="the page name on the wiki to fetch and update (the language suffix "
                     "is added automatically as necessary) (default: %(default)s)")
        # TODO: no idea how to forbid setting this globally in the config...
        group.add_argument("--summary", default="自動更新",
                help="the edit summary to use when saving the page (default: %(default)s)")
Пример #4
0
    def set_argparser(klass, argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)

        group = argparser.add_argument_group(title="script parameters")
        if klass.force_interactive is False:
            group.add_argument("-i",
                               "--interactive",
                               action="store_true",
                               help="enables interactive mode")
        group.add_argument(
            "--dry-run",
            action="store_true",
            help="enables dry-run mode (changes are only shown and discarded)")
        mode = group.add_mutually_exclusive_group()
        mode.add_argument("--first",
                          default=None,
                          metavar="TITLE",
                          help="the title of the first page to be processed")
        mode.add_argument("--title",
                          help="the title of the only page to be processed")
        group.add_argument(
            "--lang",
            default=None,
            help=
            "comma-separated list of language tags to process (default: all, choices: {})"
            .format(lang.get_internal_tags()))
Пример #5
0
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)

        group = argparser.add_argument_group(title="script parameters")
        group.add_argument("--interactive", default=True, metavar="BOOL", type=ws.config.argtype_bool, help="Enables interactive mode (default: %(default)s)")
        group.add_argument("--spam-phrases", action="append", required=True, metavar="STR", help="A phrase considered as spam (this option can be specified multiple times).")
        group.add_argument("--spam-occurrences-threshold", type=int, default=5, help="Minimal number of phrases occurring on a page that triggers the spam filter.")
Пример #6
0
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)

        argparser.add_argument("--page-name", default="ArchWiki:Maintenance Team",
                    help="the page name on the wiki to fetch and update (default: %(default)s)")
        argparser.add_argument("--days", action="store", default=30, type=int, metavar="N",
                    help="the time span in days (default: %(default)s)")
        argparser.add_argument("--min-edits", action="store", default=10, type=int, metavar="N",
                    help="minimum number of edits for moving into the \"active\" table (default: %(default)s)")
Пример #7
0
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)
        if "Database parameters" not in present_groups:
            Database.set_argparser(argparser)

        output = argparser.add_argument_group(title="output")
        # TODO: maybe leave only the short option to forbid configurability in config file
        output.add_argument('-s', '--save', action='store_true',
                        help='try to save the page (requires being logged in)')
        # FIXME: -c conflicts with -c/--config
#        output.add_argument('-c', '--clipboard', action='store_true',
        output.add_argument('--clipboard', action='store_true',
                        help='try to store the updated text in the clipboard')
        output.add_argument('-p', '--print', action='store_true',
                        help='print the updated text in the standard output '
                        '(this is the default output method)')

        usstats = argparser.add_argument_group(title="user statistics")
        usstats.add_argument('--us-days-span', action='store', default=30,
                    type=int, dest='us_days', metavar='N',
                    help='the time span in days (default: %(default)s)')
        usstats.add_argument('--us-min-tot-edits', action='store',
                    default=1000, type=int, dest='us_mintotedits', metavar='N',
                    help='minimum total edits for users with not enough '
                    'recent changes (default: %(default)s)')
        usstats.add_argument('--us-min-rec-edits', action='store',
                    default=1, type=int, dest='us_minrecedits', metavar='N',
                    help='minimum recent changes for users with not enough '
                    'total edits (default: %(default)s)')

        # TODO: main group for "script parameters" would be most logical, but
        #       but argparse does not display nested groups in the help page
        group = argparser.add_argument_group(title="other parameters")

        group.add_argument('-a', '--anonymous', action='store_true',
                    help='do not require logging in: queries may be limited to '
                    'a lower rate')
        # TODO: maybe leave only the short option to forbid configurability in config file
        group.add_argument('-f', '--force', action='store_true',
                    help='try to update the page even if it was last saved in '
                    'the same UTC day')
        group.add_argument('--statistics-page', default='ArchWiki:Statistics',
                    help='the page name on the wiki to fetch and update '
                    '(default: %(default)s)')
        # TODO: no idea how to forbid setting this globally in the config...
        group.add_argument('--summary', default='automatic update',
                    help='the edit summary to use when saving the page '
                    '(default: %(default)s)')
Пример #8
0
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)

        output = argparser.add_argument_group(title="output")
        # TODO: maybe leave only the short option to forbid configurability in config file
        output.add_argument('-s', '--save', action='store_true',
                        help='try to save the page (requires being logged in)')
        # FIXME: -c conflicts with -c/--config
#        output.add_argument('-c', '--clipboard', action='store_true',
        output.add_argument('--clipboard', action='store_true',
                        help='try to store the updated text in the clipboard')
        output.add_argument('-p', '--print', action='store_true',
                        help='print the updated text in the standard output '
                        '(this is the default output method)')

        usstats = argparser.add_argument_group(title="user statistics")
        usstats.add_argument('--us-days-span', action='store', default=30,
                    type=int, dest='us_days', metavar='N',
                    help='the time span in days (default: %(default)s)')
        usstats.add_argument('--us-min-tot-edits', action='store',
                    default=1000, type=int, dest='us_mintotedits', metavar='N',
                    help='minimum total edits for users with not enough '
                    'recent changes (default: %(default)s)')
        usstats.add_argument('--us-min-rec-edits', action='store',
                    default=1, type=int, dest='us_minrecedits', metavar='N',
                    help='minimum recent changes for users with not enough '
                    'total edits (default: %(default)s)')

        # TODO: main group for "script parameters" would be most logical, but
        #       but argparse does not display nested groups in the help page
        group = argparser.add_argument_group(title="other parameters")

        group.add_argument('-a', '--anonymous', action='store_true',
                    help='do not require logging in: queries may be limited to '
                    'a lower rate')
        # TODO: maybe leave only the short option to forbid configurability in config file
        group.add_argument('-f', '--force', action='store_true',
                    help='try to update the page even if it was last saved in '
                    'the same UTC day')
        group.add_argument('--statistics-page', default='ArchWiki:Statistics',
                    help='the page name on the wiki to fetch and update '
                    '(default: %(default)s)')
        # TODO: no idea how to forbid setting this globally in the config...
        group.add_argument('--summary', default='automatic update',
                    help='the edit summary to use when saving the page '
                    '(default: %(default)s)')
Пример #9
0
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)
        if "Database parameters" not in present_groups:
            Database.set_argparser(argparser)

        group = argparser.add_argument_group(title="script parameters")
        mode = group.add_mutually_exclusive_group()
        mode.add_argument("--first", default=None, metavar="TITLE",
                help="the title of the first page to be processed")
        mode.add_argument("--title",
                help="the title of the only page to be processed")
        group.add_argument("--lang", default="en",
                help="comma-separated list of language tags to process (default: en, choices: {})".format(lang.get_internal_tags()))
Пример #10
0
def api_mock(req_mock, module_mocker, title_context):
    # create the API object
    api_url = "http://wiki-scripts.localhost/api.php"
    index_url = "http://wiki-scripts.localhost/index.php"
    session = API.make_session()
    api = API(api_url, index_url, session)

    # register a callback function for dynamic responses
    # https://requests-mock.readthedocs.io/en/latest/response.html#dynamic-response
    def api_callback(request, context):
        params = request.qs
        if params.get("format") == ["json"
                                    ] and params.get("action") == ["query"]:
            if params.get("meta") == ["siteinfo"] and params.get("siprop") == [
                    "general"
            ]:
                # only props which may be relevant for tests are in the mocked response
                general = {
                    "mainpage": "Main page",
                    "base":
                    "http://wiki-scripts.localhost/index.php/Main_page",
                    "sitename": "wiki-scripts tests",
                    "articlepath": "/index.php/$1",
                    "scriptpath": "",
                    "script": "/index.php",
                    "server": "http://wiki-scripts.localhost",
                    "servername": "wiki-scripts.localhost",
                }
                return {"batchcomplete": "", "query": {"general": general}}
        # defaults
        context.status_code = 404
        context.reason = "Missing mock for the query parameters '{}'".format(
            request.qs)

    req_mock.get(api_url, json=api_callback)
    req_mock.get(index_url,
                 status_code=404,
                 reason="Missing mocks for the index.php entry point")

    # mock the title context class
    mContext = module_mocker.patch(
        "ws.parser_helpers.title.Context",
        module_mocker.create_autospec(title_context))
    # override the from_api method to always return the fixture
    mContext.from_api = lambda api: title_context

    return api
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)

        group = argparser.add_argument_group(title="script parameters")
        group.add_argument("--tmp-dir", type=ws.config.argtype_dirname_must_exist, metavar="PATH", default="/tmp/wiki-scripts/",
                help="temporary directory path (will be created if necessary, but parent directory must exist) (default: %(default)s)")
        group.add_argument("-i", "--interactive", action="store_true",
                help="run in interactive mode (should be used for testing)")
        group.add_argument("--aurpkgs-url", default="https://aur.archlinux.org/packages.gz", metavar="URL",
                help="the URL to packages.gz file on the AUR (default: %(default)s)")
        group.add_argument("--report-dir", type=ws.config.argtype_existing_dir, default=".", metavar="PATH",
                help="directory where the report should be saved (default: %(default)s)")
        group.add_argument("--report-page", type=str, default=None, metavar="PATH",
                help="existing report page on the wiki (default: %(default)s)")
Пример #12
0
    def set_argparser(argparser):
        # first try to set options for objects we depend on
        present_groups = [group.title for group in argparser._action_groups]
        if "Connection parameters" not in present_groups:
            API.set_argparser(argparser)
        if "Database parameters" not in present_groups:
            Database.set_argparser(argparser)

        group = argparser.add_argument_group(title="script parameters")
        group.add_argument("-i", "--interactive", action="store_true",
                help="enables interactive mode")
        group.add_argument("--dry-run", action="store_true",
                help="enables dry-run mode (changes are only shown and discarded)")
        mode = group.add_mutually_exclusive_group()
        mode.add_argument("--first", default=None, metavar="TITLE",
                help="the title of the first page to be processed")
        mode.add_argument("--title",
                help="the title of the only page to be processed")
        group.add_argument("--lang", default=None,
                help="comma-separated list of language tags to process (default: all, choices: {})".format(lang.get_internal_tags()))
Пример #13
0
 def from_argparser(klass, args, api=None):
     if api is None:
         api = API.from_argparser(args)
     if args.lang:
         tags = args.lang.split(",")
         for tag in tags:
             if tag not in lang.get_internal_tags():
                 # FIXME: more elegant solution
                 raise Exception("{} is not a valid language tag".format(tag))
         langnames = {lang.langname_for_tag(tag) for tag in tags}
     else:
         langnames = set()
     interactive = args.interactive if klass.force_interactive is False else True
     return klass(api, interactive=interactive, dry_run=args.dry_run, first=args.first, title=args.title, langnames=langnames)
Пример #14
0
 def from_argparser(klass, args, api=None, db=None):
     if api is None:
         api = API.from_argparser(args)
     if db is None:
         db = Database.from_argparser(args)
     if args.lang:
         tags = args.lang.split(",")
         for tag in tags:
             if tag not in lang.get_internal_tags():
                 # FIXME: more elegant solution
                 raise Exception("{} is not a valid language tag".format(tag))
         langnames = {lang.langname_for_tag(tag) for tag in tags}
     else:
         langnames = set()
     return klass(api, db, interactive=args.interactive, dry_run=args.dry_run, first=args.first, title=args.title, langnames=langnames, connection_timeout=args.connection_timeout, max_retries=args.connection_max_retries)
Пример #15
0
 def from_argparser(klass, args, api=None, db=None):
     if api is None:
         api = API.from_argparser(args)
     if db is None:
         db = Database.from_argparser(args)
     if args.lang:
         tags = args.lang.split(",")
         for tag in tags:
             if tag not in lang.get_internal_tags():
                 # FIXME: more elegant solution
                 raise Exception("{} is not a valid language tag".format(tag))
         langnames = {lang.langname_for_tag(tag) for tag in tags}
     else:
         langnames = set()
     return klass(api, db, first=args.first, title=args.title, langnames=langnames, connection_timeout=args.connection_timeout, max_retries=args.connection_max_retries)
Пример #16
0
 def from_argparser(klass, args, api=None):
     if api is None:
         api = API.from_argparser(args)
     return klass(api, args)
Пример #17
0
 def from_argparser(klass, args, api=None, db=None):
     if api is None:
         api = API.from_argparser(args)
     if db is None:
         db = Database.from_argparser(args)
     return klass(api, db, args)
Пример #18
0
#! /usr/bin/env python3

import os.path
import datetime

from ws.client import API

api_url = "https://wiki.archlinux.org/api.php"
index_url = "https://wiki.arclinux.org/index.php"
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")
session = API.make_session(ssl_verify=True, cookie_file=cookie_path)

api = API(api_url, index_url, session)

# get list of all users, who:
#   - are not bots
#   - made at least one edit
#   - have been active in the last 30 days
#   - are not blocked
# the list can be sorted by:
#   - editcount
#   - recenteditcount
#   - avgeditsperday (needs to be calculated)

users = list(
    api.list(list="allusers",
             aulimit="max",
             auprop="blockinfo|editcount|registration",
             auexcludegroup="bot",
             auwitheditsonly="",
             auactiveusers=""))
#! /usr/bin/env python3

import os.path
from collections import namedtuple
import itertools

from ws.client import API
import ws.ArchWiki.lang as lang

api_url = "https://wiki.archlinux.org/api.php"
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")

api = API(api_url, cookie_file=cookie_path, ssl_verify=True)

Page = namedtuple("Page", ["title", "langname", "pure"])

pages = []
for page in api.generator(generator="allpages", gaplimit="max", gapfilterredir="nonredirects"):
    pure, langname = lang.detect_language(page["title"])
    pages.append(Page(page["title"], langname, pure))

pages.sort(key=lambda page: (page.langname, page.pure))

groups = itertools.groupby(pages, key=lambda page: page.langname)
for langname, pages in groups:
    print("== {} ==\n".format(langname))
    for page in pages:
        print("* [[:{}|{}]]".format(page.title, page.pure))
    print()
Пример #20
0
#! /usr/bin/env python3

import os.path

from ws.client import API
from ws.diff import RevisionDiffer

api_url = "https://wiki.archlinux.org/api.php"
index_url = "https://wiki.arclinux.org/index.php"
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")
session = API.make_session(ssl_verify=True, cookie_file=cookie_path)

api = API(api_url, index_url, session)

# show the diff for two revisions, colorized for 256-color terminal
oldrevid = 625761
newrevid = 625800

diff = RevisionDiffer(api)
print(diff.diff(oldrevid, newrevid))
Пример #21
0
#! /usr/bin/env python3

import os.path

from ws.client import API
from ws.diff import diff_revisions

api_url = "https://wiki.archlinux.org/api.php"
index_url = "https://wiki.arclinux.org/index.php"
session = API.make_session()

api = API(api_url, index_url, session)


# show the diff for two revisions, colorized for 256-color terminal
oldrevid = 625761
newrevid = 625800

print(diff_revisions(api, oldrevid, newrevid))
Пример #22
0
    logger.info("Plotting hist_active_users.png")
    hist_active_users = []
    num_bins = len(bin_edges) - 1
    for i in range(num_bins):
        # array of indexes for revisions in current bin
        current_bin, = np.where(bin_indexes == i)
        active_users = list(set([revisions[ii]["user"] for ii in current_bin]))
        hist_active_users.append(len(active_users))

    plot_date_bars(hist_active_users, bin_edges,
            title="ArchWiki active users per month", ylabel="active users",
            fname="stub/hist_active_users.png")


if __name__ == "__main__":
    import ws.config
    import ws.logging

    argparser = ws.config.getArgParser(description="Create histogram charts for the statistics page")
    API.set_argparser(argparser)
    # TODO: script-specific arguments (e.g. output path)
    args = argparser.parse_args()

    # set up logging
    ws.logging.init(args)

    api = API.from_argparser(args)
    db = ws.cache.AllRevisionsProps(api, args.cache_dir)

    create_histograms(db["revisions"])
Пример #23
0
 def from_argparser(klass, args, api=None):
     if api is None:
         api = API.from_argparser(args)
     return klass(api, args.aurpkgs_url, args.tmp_dir, args.ssl_verify,
                  args.report_dir, args.report_page, args.interactive)
Пример #24
0
#! /usr/bin/env python3

import os.path

from ws.client import API

api_urls = [
    "https://wiki.archlinux.org/api.php",
    "https://wiki.archlinux.de/api.php",
]
index_url = "https://wiki.arclinux.org/index.php"
session = API.make_session()

for api_url in api_urls:
    api = API(api_url, index_url, session)
    prefixes = set()
    for ns in api.site.namespaces:
        if ns < 0:
            continue
        for page in api.generator(generator="allpages",
                                  gaplimit="max",
                                  gapfilterredir="nonredirects",
                                  gapnamespace=ns,
                                  prop="iwlinks",
                                  iwprop="url",
                                  iwlimit="max"):
            for link in page.get("iwlinks", []):
                prefixes.add(link["prefix"])
    print("interwiki prefixes used on {}:".format(api.get_hostname()))
    print(sorted(prefixes))
Пример #25
0
 def from_argparser(klass, args, api=None, db=None):
     if api is None:
         api = API.from_argparser(args)
     if db is None:
         db = Database.from_argparser(args)
     return klass(api, db, args.page_name, args.days, args.min_edits)
Пример #26
0
#! /usr/bin/env python3

import os.path

from ws.client import API

api_urls = [
    "https://wiki.archlinux.org/api.php",
    "https://wiki.archlinux.de/api.php",
]
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")

for api_url in api_urls:
    api = API(api_url, cookie_file=cookie_path, ssl_verify=True)
    prefixes = set()
    for ns in api.site.namespaces:
        if ns < 0:
            continue
        for page in api.generator(generator="allpages", gaplimit="max", gapfilterredir="nonredirects", gapnamespace=ns, prop="iwlinks", iwprop="url", iwlimit="max"):
            for link in page.get("iwlinks", []):
                prefixes.add(link["prefix"])
    print("interwiki prefixes used on {}:".format(api.get_hostname()))
    print(sorted(prefixes))
Пример #27
0
#! /usr/bin/env python3

import os.path

from ws.client import API
from ws.diff import RevisionDiffer

api_url = "https://wiki.archlinux.org/api.php"
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")

api = API(api_url, cookie_file=cookie_path, ssl_verify=True)

# show the diff for two revisions, colorized for 256-color terminal
oldrevid = 325013
newrevid = 325254

diff = RevisionDiffer(api)
print(diff.diff(oldrevid, newrevid))
Пример #28
0
 def from_argparser(klass, args, api=None):
     if api is None:
         api = API.from_argparser(args)
     return klass(api, args.spam_phrases, args.spam_occurrences_threshold, args.interactive)
Пример #29
0
 def from_argparser(klass, args, api=None):
     if api is None:
         api = API.from_argparser(args)
     return klass(api, args.cache_dir, args.page_name, args.days, args.min_edits)
#! /usr/bin/env python3

import os.path
from collections import namedtuple
import itertools

from ws.client import API
import ws.ArchWiki.lang as lang

api_url = "https://wiki.archlinux.org/api.php"
index_url = "https://wiki.arclinux.org/index.php"
session = API.make_session()

api = API(api_url, index_url, session)

Page = namedtuple("Page", ["title", "langname", "pure"])

pages = []
for page in api.generator(generator="allpages",
                          gaplimit="max",
                          gapfilterredir="nonredirects"):
    pure, langname = lang.detect_language(page["title"])
    pages.append(Page(page["title"], langname, pure))

pages.sort(key=lambda page: (page.langname, page.pure))

groups = itertools.groupby(pages, key=lambda page: page.langname)
for langname, pages in groups:
    print("== {} ==\n".format(langname))
    for page in pages:
        print("* [[:{}|{}]]".format(page.title, page.pure))
Пример #31
0
                    xy=(x, y),
                    xytext=(5, 0),
                    textcoords="offset points",
                    ha="left",
                    va="top")


def plot_save(fname):
    plt.savefig(fname, dpi=192)


if __name__ == "__main__":
    import ws.config

    argparser = ws.config.getArgParser()
    API.set_argparser(argparser)
    Database.set_argparser(argparser)

    args = ws.config.parse_args(argparser)

    api = API.from_argparser(args)
    require_login(api)
    db = Database.from_argparser(args)

    users = [
        "Alad", "Fengchao", "Indigo", "Kynikos", "Lahwaacz", "Lonaowna",
        "Nl6720"
    ]

    all_logs = list(db.query(list="logevents", letype="rights", ledir="newer"))
Пример #32
0
 def from_argparser(klass, args, api=None):
     if api is None:
         api = API.from_argparser(args)
     return klass(api, args)
Пример #33
0
#! /usr/bin/env python3

import os.path

from ws.client import API

api_url = "https://wiki.archlinux.org/api.php"
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")

api = API(api_url, cookie_file=cookie_path, ssl_verify=True)

# allpages
# see list of parameters: https://www.mediawiki.org/wiki/API:Allpages
for page in api.generator(generator="allpages", gaplimit="max"):
    print(page["title"])

# allcategories
# see list of parameters: https://www.mediawiki.org/wiki/API:Allcategories
#for page in api.generator(generator="allcategories", gaclimit="max"):
#    print(page["title"])

# categorymembers
# see list of parameters: https://www.mediawiki.org/wiki/API:Categorymembers
#for page in api.generator(generator="categorymembers", gcmtitle="Category:English", gcmlimit="max"):
#    print(page["title"])

# transclusions
# see list of parameters: https://www.mediawiki.org/wiki/API:Embeddedin
#for page in api.generator(generator="embeddedin", geititle="Template:AUR", geilimit="max"):
#    print(page["title"])
Пример #34
0
#! /usr/bin/env python3

import os.path

from ws.client import API

api_url = "https://wiki.archlinux.org/api.php"
index_url = "https://wiki.arclinux.org/index.php"
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")
session = API.make_session(ssl_verify=True, cookie_file=cookie_path)

api = API(api_url, index_url, session)

# allpages
# see list of parameters: https://www.mediawiki.org/wiki/API:Allpages
for page in api.generator(generator="allpages", gaplimit="max"):
    print(page["title"])

# allcategories
# see list of parameters: https://www.mediawiki.org/wiki/API:Allcategories
#for page in api.generator(generator="allcategories", gaclimit="max"):
#    print(page["title"])

# categorymembers
# see list of parameters: https://www.mediawiki.org/wiki/API:Categorymembers
#for page in api.generator(generator="categorymembers", gcmtitle="Category:English", gcmlimit="max"):
#    print(page["title"])

# transclusions
# see list of parameters: https://www.mediawiki.org/wiki/API:Embeddedin
#for page in api.generator(generator="embeddedin", geititle="Template:AUR", geilimit="max"):
Пример #35
0
#! /usr/bin/env python3

import os.path
import datetime

from ws.client import API

api_url = "https://wiki.archlinux.org/api.php"
cookie_path = os.path.expanduser("~/.cache/ArchWiki.cookie")

api = API(api_url, cookie_file=cookie_path, ssl_verify=True)

# get list of all users, who:
#   - are not bots
#   - made at least one edit
#   - have been active in the last 30 days
#   - are not blocked
# the list can be sorted by:
#   - editcount
#   - recenteditcount
#   - avgeditsperday (needs to be calculated)

users = list(api.list(list="allusers", aulimit="max", auprop="blockinfo|editcount|registration", auexcludegroup="bot", auwitheditsonly="", auactiveusers=""))

users = [user for user in users if user.get("blockid") is None]

# prepare sorting by avgeditsperday
now = datetime.datetime.utcnow()
for user in users:
    # exclude users with no registration date (some weird anomaly)  TODO: investigate
    if user["registration"] == "":
Пример #36
0
#! /usr/bin/env python3

import os.path

from ws.client import API

api_url = "https://wiki.archlinux.org/api.php"
index_url = "https://wiki.arclinux.org/index.php"
session = API.make_session()

api = API(api_url, index_url, session)

# allpages
# see list of parameters: https://www.mediawiki.org/wiki/API:Allpages
for page in api.generator(generator="allpages", gaplimit="max"):
    print(page["title"])

# allcategories
# see list of parameters: https://www.mediawiki.org/wiki/API:Allcategories
#for page in api.generator(generator="allcategories", gaclimit="max"):
#    print(page["title"])

# categorymembers
# see list of parameters: https://www.mediawiki.org/wiki/API:Categorymembers
#for page in api.generator(generator="categorymembers", gcmtitle="Category:English", gcmlimit="max"):
#    print(page["title"])

# transclusions
# see list of parameters: https://www.mediawiki.org/wiki/API:Embeddedin
#for page in api.generator(generator="embeddedin", geititle="Template:AUR", geilimit="max"):
#    print(page["title"])