887

· 👁 11 views

#commons: #count uploads from a specific user for a period of time, #python:

import requests

user = 'Globustut'
start = '2026-01-20T00:00:00Z'  # newer
end   = '2026-01-01T00:00:00Z'  # older

params = {
    'action': 'query',
    'format': 'json',
    'list': 'usercontribs',
    'ucuser': user,
    'ucnamespace': '6',
    'ucshow': 'new',
    'ucstart': start,
    'ucend': end,
    'uclimit': 'max',
}
headers = {'User-Agent': 'commons-upload-count/1.0'}

total = 0
s = requests.Session()
while True:
    data = s.get('https://commons.wikimedia.org/w/api.php', params=params, headers=headers, timeout=30).json()
    total += len(data.get('query', {}).get('usercontribs', []))
    if 'continue' not in data:
        break
    print('.', end='')
    params.update(data['continue'])

print(total)

https://quarry.wmcloud.org/query/100891