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)" )
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()))
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)")
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)")
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.")
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)")
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)')
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)')
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()))
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)")
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()))
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"])
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"))