Skip to content

Instantly share code, notes, and snippets.

@lucaswerkmeister
Created April 15, 2019 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucaswerkmeister/565fb571ae09281a43981d9c07e42373 to your computer and use it in GitHub Desktop.
Save lucaswerkmeister/565fb571ae09281a43981d9c07e42373 to your computer and use it in GitHub Desktop.
play with it in the Python REPL:
import mwapi
import mwoauth
import requests_oauthlib
consumer_token = mwoauth.ConsumerToken('6140cbbec457160563327ae26a03c3f9', '159e15a7d4d2abd6e4dd09a85523f68fd6d84742')
url, request_token = mwoauth.initiate('http://localhost/wiki1/index.php', consumer_token)
print(url)
# visit the URL, accept, copy query string of redirect target (after the '?')
access_token = mwoauth.complete('http://localhost/wiki1/index.php', consumer_token, request_token, QUERY_STRING_FROM_REDIRECTED_URL)
auth = requests_oauthlib.OAuth1(client_key=consumer_token.key, client_secret=consumer_token.secret, resource_owner_key=access_token.key, resource_owner_secret=access_token.secret)
session = mwapi.Session(host='http://localhost', api_path='/wiki1/api.php', auth=auth)
session.post(action='patrol', revid=2061, token=session.get(action='query', meta='tokens', type='patrol')['query']['tokens']['patroltoken'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment