Import User:YuviPanda/replicahelper.ipynb for easy access to db replicas

from paws.YuviPanda.replicahelper import sql
def namespace_edits(users, start, end, dbs):
    user_ids = ','.join([str(u) for u in users])
    namespaces = [0, 1, 2, 3]
    result = sql("""
       select count(wat.user_id) as edits
       from (select r.rev_user as user_id
               from revision_userindex r
                    inner join
                    page p      
                    on p.page_id = r.rev_page
              where r.rev_timestamp between :start and :end
                and r.rev_user_text in :user_ids
                and p.page_namespace in :namespaces

              union all

             select a.ar_user as user_id
               from archive_userindex a
              where a.ar_timestamp between :start and :end
                and a.ar_user_text in :user_ids
                and a.ar_namespace in :namespaces
            ) as wat
      group by user_id""", {
        'start': start,
        'end': end,
        'user_ids': users,
        'namespaces': namespaces
    }, dbs)
    for row in result:
        print(row)
from ipywidgets import interact_manual
@interact_manual
def edits(users='', wikis='enwiki_p'):
    namespace_edits(
        users.split(','), 
        '20060101000000', 
        '20161001000000', 
        wikis.split(',')
    )