Esempio n. 1
0
def main(func, list_home=None, target_list=None, search_target=None, limit=DEFAULT_FETCH_LIMIT, **kw):
    list_home = list_home or os.getcwd()
    if not os.path.isdir(list_home):
        raise IOError("not a directory: " + str(list_home))
    if target_list:
        if os.path.isfile(target_list):
            target_list_path = target_list
        else:
            alm = ArticleListManager(search_path=[list_home])
            target_list_path = alm.lookup(target_list)
    else:
        target_list_path = None
    if func is show:
        path = target_list_path or list_home
        show(path)
    elif func is create:
        outfile = list_home + "/" + target_list + DEFAULT_EXT
        if not target_list:
            raise IOError("not a valid filename: %s" % target_list)
        if target_list_path:
            raise IOError("list already exists: %s" % target_list_path)
        codecs.open(outfile, "w", encoding="utf-8").close()
        print "Created article list %s" % outfile
    else:
        outfile = list_home + "/" + target_list + DEFAULT_EXT
        if not target_list_path:
            raise IOError("file not found for target list: %s" % target_list)
        a_list = ArticleList.from_file(outfile)
        if search_target.startswith("Category:"):
            article_list = wapiti.get_category_recursive(search_target, count=limit, to_zero_ns=True)
        elif search_target.startswith("Template:"):
            article_list = wapiti.get_transcluded(page_title=search_target, limit=limit, to_zero_ns=True)
        if func is include:
            a_list.include([a[2] for a in article_list], source=DEFAULT_SOURCE, term=search_target)
            a_list.write(outfile)
        if func is exclude:
            a_list.exclude([a[2] for a in article_list], source=DEFAULT_SOURCE, term=search_target)
            a_list.write(outfile)
        import pdb

        pdb.set_trace()
Esempio n. 2
0
def main():
    opts, args = parse_args()
    kwargs = opts.__dict__
    # TODO: better output filenames

    if kwargs.get("random"):
        print "Fetching ", opts.limit, " random articles..."
        page_ds = wapiti.get_random(opts.limit)
        filename = get_filename("random")
    elif kwargs.get("recursive"):
        print "Fetching members of category", opts.category, "..."
        page_ds = wapiti.get_category_recursive(opts.category, count=opts.limit, to_zero_ns=True)
        filename = get_filename(opts.category[:15])
    else:
        print "Fetching members of category", opts.category, "..."
        page_ds = wapiti.get_category(opts.category, count=opts.limit, to_zero_ns=True)
        filename = get_filename(opts.category[:15])

    res_filename = "results/" + filename + ".json"
    report_filename = "results/" + filename + "-report.html"

    lpr = Louper(page_ds, filename=res_filename, inputs=DEFAULT_INPUTS, **kwargs)

    dash = LoupeDashboard(lpr)
    dash.run()

    try:
        lpr.run()
    finally:
        lpr.close()
        with codecs.open(report_filename, "w", "utf-8") as rf:
            rf.write(dash.get_report())
        if kwargs.get("debug"):
            import pdb

            pdb.set_trace()