def edit_wiki_page(page_name, content, summary=None):
access_token = flask.session.get('access_token', None)
auth = OAuth1(
app.config['CONSUMER_KEY'],
app.config['CONSUMER_SECRET'],
access_token['key'],
access_token['secret'])
# Get token
r = requests.get('https://en.wikipedia.org/w/api.php', params={
'action':'query',
'meta':'tokens',
'format': 'json',
}, auth=auth)
r.raise_for_status()
token = r.json()['query']['tokens']['csrftoken']
r = requests.post('https://en.wikipedia.org/w/api.php', data={
'action':'edit',
'title': page_name,
'text': content,
'summary': summary,
'format': 'json',
'token': token,
'watchlist': 'nochange',
}, auth=auth)
r.raise_for_status()
评论列表
文章目录