Page MenuHomePhabricator
Paste P14376

Python script to flood item IDs to test T272032
ActivePublic

Authored by Lucas_Werkmeister_WMDE on Tue, Feb 16, 12:42 PM.
#!/usr/bin/env python3
from getpass import getpass
import json
import mwapi
session = mwapi.Session('https://test.wikidata.org',
user_agent='test T272032 (lucas.werkmeister@wikimedia.de)')
lgtoken = session.get(action='query',
meta='tokens',
type='login')['query']['tokens']['logintoken']
session.post(action='login',
lgname=input('Bot username: '),
lgpassword=getpass('Bot password: '),
lgtoken=lgtoken)
token = session.get(action='query',
meta='tokens')['query']['tokens']['csrftoken']
def marker_item():
return session.post(action='wbeditentity',
new='item',
token=token,
data=json.dumps({
'labels': {
'en': {
'value': 'T272032 marker item',
'language': 'en',
},
},
}))['entity']['id']
print(marker_item())
error_types = {}
for _ in range(0, 150):
try:
session.post(action='wbeditentity',
new='item',
token=token,
data=json.dumps({
'labels': {
'nosuchlanguage': 'do not use this',
},
}))
raise RuntimeError('API request should have failed')
except mwapi.errors.APIError as e:
error_types[e.code] = error_types.get(e.code, 0) + 1
print(error_types)
print(marker_item())