2 Prints out session information for user "TextAccountForMWUtils"
4 from mw.api import Session
5 from mw.lib import sessions
7 # Gather a user's revisions from the API
8 api_session = Session("https://en.wikipedia.org/w/api.php")
9 revs = api_session.user_contribs.query(
10 user={"TestAccountForMWUtils"},
13 rev_events = ((rev['user'], rev['timestamp'], rev) for rev in revs)
15 # Extract and print sessions
16 for user, session in sessions.cluster(rev_events):
17 print("{0}'s session with {1} revisions".format(user, len(session)))