« Newpagescreationbot » : différence entre les versions
Aller à la navigation
Aller à la recherche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 11 : | Ligne 11 : | ||
user='testbot' | user='testbot' | ||
passw= | passw='dhbot2017' | ||
baseurl='http://wikipast.epfl.ch/wikipast/' | baseurl='http://wikipast.epfl.ch/wikipast/' | ||
summary='Wikipastbot update' | |||
summary=' | |||
names=['Madame X','Monsieur Y'] | names=['Madame X','Monsieur Y'] | ||
# Login request | # Login request | ||
r1=requests.post(baseurl+'api.php' | payload={'action': 'query', 'format': 'json', 'utf8': '', 'meta': 'tokens', 'type': 'login'} | ||
r1=requests.post(baseurl + 'api.php', data=payload) | |||
#login confirm | #login confirm | ||
login_token=r1.json()['query']['tokens']['logintoken'] | |||
r2=requests.post(baseurl+'api.php' | payload={'action':'login','format':'json','utf8':'','lgname':user,'lgpassword':passw,'lgtoken':login_token} | ||
r2=requests.post(baseurl + 'api.php', data=payload, cookies=r1.cookies) | |||
#get edit token2 | #get edit token2 | ||
params3='?format=json&action=query&meta=tokens&continue=' | params3='?format=json&action=query&meta=tokens&continue=' | ||
r3=requests.get(baseurl+'api.php'+params3,cookies=r2.cookies) | r3=requests.get(baseurl + 'api.php' + params3, cookies=r2.cookies) | ||
edit_token=r3.json()['query']['tokens']['csrftoken'] | edit_token=r3.json()['query']['tokens']['csrftoken'] | ||
Ligne 44 : | Ligne 43 : | ||
content+='=== Archives Le Temps ===\n' | content+='=== Archives Le Temps ===\n' | ||
# save action | # save action | ||
payload={'action': 'edit', 'assert': 'user', 'format': 'json', 'utf8': '', 'text': content,'summary': summary,'title':name,'token':edit_token} | |||
payload={'action':'edit','assert':'user','format':'json','text':content,'summary':summary,'title':name,'token':edit_token} | r4=requests.post(baseurl+'api.php',data=payload,cookies=edit_cookie) | ||
r4=requests.post(baseurl+'api.php' | |||
print(r4.text) | print(r4.text) | ||
</nowiki> | </nowiki> |
Version du 19 mars 2017 à 09:27
Exemples de page créée par le bot
Code
# -*- coding: utf-8 -*- import urllib2 import requests user='testbot' passw='dhbot2017' baseurl='http://wikipast.epfl.ch/wikipast/' summary='Wikipastbot update' names=['Madame X','Monsieur Y'] # Login request payload={'action': 'query', 'format': 'json', 'utf8': '', 'meta': 'tokens', 'type': 'login'} r1=requests.post(baseurl + 'api.php', data=payload) #login confirm login_token=r1.json()['query']['tokens']['logintoken'] payload={'action':'login','format':'json','utf8':'','lgname':user,'lgpassword':passw,'lgtoken':login_token} r2=requests.post(baseurl + 'api.php', data=payload, cookies=r1.cookies) #get edit token2 params3='?format=json&action=query&meta=tokens&continue=' r3=requests.get(baseurl + 'api.php' + params3, cookies=r2.cookies) edit_token=r3.json()['query']['tokens']['csrftoken'] edit_cookie=r2.cookies.copy() edit_cookie.update(r3.cookies) for name in names: content='' content+='==Biographie==\n' content+='Veuillez écrire une biographie ici\n' content+='==Références==\n' content+='=== Ngrams viewer ===\n' name_ngv=name.lower().replace(" ","%20") content+='[http://dhlabsrv4.epfl.ch/ngviewer.php?mode=1&req_1='+name_ngv+' '+name+']\n' content+='=== Archives Le Temps ===\n' # save action payload={'action': 'edit', 'assert': 'user', 'format': 'json', 'utf8': '', 'text': content,'summary': summary,'title':name,'token':edit_token} r4=requests.post(baseurl+'api.php',data=payload,cookies=edit_cookie) print(r4.text)