コード例 #1
0
def run(revs, radius, cutoff):
    writer = None
    for wiki, revs in aggregate(revs, by=lambda r: r.wiki):

        sys.stderr.write("Conn({0}): ".format(wiki))
        db = DB.from_params(
            host="analytics-store.eqiad.wmnet", user="******", read_default_file="~/.my.research.cnf", db=wiki
        )
        for rev in revs:
            if writer == None:
                writer = tsv.Writer(sys.stdout, headers=rev.keys() + ["reverted", "archived"])

            rev_doc = dict(rev)

            try:
                # sys.stderr.write("<");sys.stderr.flush()
                rev_row = db.revisions.get(int(rev.rev_id))
                # sys.stderr.write(str(int(rev_row==None)))
                # sys.stderr.write("|");sys.stderr.flush()
                rev_doc["archived"] = False

                revert = reverts.database.check_row(
                    db, rev_row, radius=radius, before=Timestamp(rev_row["rev_timestamp"]) + cutoff
                )
                if revert != None:
                    rev_doc["reverted"] = True
                    sys.stderr.write("r")
                    sys.stderr.flush()
                else:
                    rev_doc["reverted"] = False
                    sys.stderr.write(".")
                    sys.stderr.flush()

            except KeyError:
                rev_doc["archived"] = False
                rev_doc["reverted"] = None
                sys.stderr.write("a")
                sys.stderr.flush()
            finally:
                # sys.stderr.write(">");sys.stderr.flush()
                pass

            writer.write([rev_doc[k] for k in rev.keys() + ["reverted", "archived"]])

            sys.stderr.flush()

        sys.stderr.write("\n")
        sys.stderr.flush()
コード例 #2
0
import sys,os;sys.path.insert(0, os.path.abspath(os.getcwd()))
from mw.database import DB
from mw.lib import reverts

db = DB.from_params(
	host="s1-analytics-slave.eqiad.wmnet", 
	read_default_file="~/.my.cnf", 
	user="******", 
	db="enwiki"
)
revisions = db.revisions.query(user_id=9133062)

for rev_row in revisions:
	revert = reverts.database.check_row(db, rev_row)
	if revert != None: 
		print("{0} reverted {1} to {2}".format(
				revert.reverting['rev_id'],
				rev_row['rev_id'],
				revert.reverted_to['rev_id']
			)
		)

コード例 #3
0
"""
Prints the reverting rev_id, rev_id and reverted to rev_id of all reverted
revisions made by user with ID 9133062.
"""
from mw.database import DB
from mw.lib import reverts

db = DB.from_params(host="s1-analytics-slave.eqiad.wmnet",
                    read_default_file="~/.my.cnf",
                    user="******",
                    db="enwiki")
revisions = db.revisions.query(user_id=9133062)

for rev_row in revisions:
    revert = reverts.database.check_row(db, rev_row)
    if revert is not None:
        print("{0} reverted {1} to {2}".format(revert.reverting['rev_id'],
                                               rev_row['rev_id'],
                                               revert.reverted_to['rev_id']))