def run(api_host, rev_ids, labels, trusted_groups, trusted_edits,
        revert_radius, revert_window, threads, verbose):

    # Construct our API session
    session = mwapi.Session(api_host,
                            user_agent="editquality -- Labeling script.")

    def prelabel(rev_ids):
        # Get a document for each revision from the API
        rev_docs = query_revisions_by_revids(session, revids=rev_ids,
                                             rvprop=['ids', 'user', 'userid'])
        for rev_doc in rev_docs:
            try:
                rev_id, page_id = rev_doc['revid'], rev_doc['page']['pageid']
                user_id, user_text = rev_doc.get('userid'), rev_doc.get('user')

                if user_id is not None and user_id > 0 and \
                   trusted_groups is not None and \
                   user_in_trusted_group(session, user_text, trusted_groups):
                    # If user in trusted groups
                    yield rev_doc['revid'], False, "trusted group"

                elif user_id is not None and user_id > 0 and \
                     trusted_edits is not None and \
                   user_has_trusted_edits(session, user_text, trusted_edits):
                    # If user has trusted total edits
                    yield rev_doc['revid'], False, "trusted edits"

                elif user_was_blocked(session, user_text):
                    # Check whether this user was blocked
                    yield rev_doc['revid'], True, "blocked user"

                elif edit_was_reverted(session, rev_id, page_id, revert_radius,
                                       revert_window):
                    # Check if the edit was reverted (slow)
                    yield rev_doc['revid'], True, "reverted edit"

                else:
                    # We don't know what's up
                    yield rev_doc['revid'], True, None
            except Exception:
                sys.stderr.write(traceback.format_exc())

    rev_id_chunks = chunk(rev_ids, 50)
    rev_review_reasons = para.map(prelabel, rev_id_chunks, mappers=threads)
    for rev_id, needs_review, reason in rev_review_reasons:
        if verbose:
            if not needs_review:
                sys.stderr.write(".")
            else:
                sys.stderr.write((reason or "?")[0])

            sys.stderr.flush()

        labels.write([rev_id, needs_review, reason])

    if verbose:
        sys.stderr.write("\n")
        sys.stderr.flush()
dataset/ETHPy150Open wiki-ai/editquality/editquality/utilities/prelabel.py/run/original