Пример #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)

        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()))
Пример #2
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)"
        )
Пример #3
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)')
Пример #4
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()))
Пример #5
0
                    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"))

    ax = plot_setup()
    db.update_parser_cache()

    namespaces = ["1", "5", "11", "13", "15"]
    talks = OrderedSet()
    for ns in namespaces:
        for page in db.query(generator="allpages", gapnamespace=ns, prop="sections", secprop={"title"}):
            for section in page.get("sections", []):
                if section["title"].startswith("<s>") and section["title"].endswith("</s>"):
                    talks.add(page["title"])

    for talk in talks:
        print("* [[{}]]".format(talk))

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

    argparser = ws.config.getArgParser(description="Find closed discussions")
    API.set_argparser(argparser)
    Database.set_argparser(argparser)

    args = argparser.parse_args()

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

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

    main(api, db)