Programmeren in Python/Pywikibot: verschil tussen versies

Verwijderde inhoud Toegevoegde inhoud
RonnieV (overleg | bijdragen)
→‎Gebruiker e-mailen: Voordat er iemand geëmailleerd wordt
Lintfouten: Verouderde HTML-elementen
Regel 16:
 
==Wikidata redirect==
<sourcesyntaxhighlight lang="python">
x = pywikibot.ItemPage(repo, 'Q18362289') #this one is a redirect
while x.isRedirectPage(): #controleer of dit een redirect is
Regel 22:
print("Ik heb 'm [%s]" % (x.title()))
 
</syntaxhighlight>
</source>
==Alle pagina's uit een categorie==
<sourcesyntaxhighlight lang="python">
import pywikibot
from pywikibot import pagegenerators
Regel 36:
print(page.title())
print("Klaar")
</syntaxhighlight>
</source>
 
==Alle pagina's uit een categorie, met andere taalversies==
<sourcesyntaxhighlight lang="python">
 
 
Regel 75:
print("[%s]-[%s]" % (page.site.lang, page.title()))
print("Klaar")
</syntaxhighlight>
</source>
 
==Gebruiker e-mailen==
<sourcesyntaxhighlight lang="python">
import pywikibot
 
Regel 88:
 
wikiuser.sendMail(subject='bot-mail-subject',text='Hoi, het is gelukt! Ik kan naar een wiki-username een mail sturen, en het subject en de body van de e-mail kan ik zelf bepalen!')
</syntaxhighlight>
</source>
 
==Wikidata property==
<sourcesyntaxhighlight lang="python">
site=pywikibot.site()
repo=site.data_repository()
Regel 98:
for x in (dir(pp)):
print(x)
</syntaxhighlight>
</source>
 
==Alle links op een pagina==
<sourcesyntaxhighlight lang="python">
#import pywikibot
site=pywikibot.Site('nl')
Regel 107:
for onelink in page.linkedPages():
print(onelink)
</syntaxhighlight>
</source>
 
==Alle links naar deze pagina==
<sourcesyntaxhighlight lang="python">
#import pywikibot
site=pywikibot.Site('nl')
Regel 116:
for onelink in page.backlinks():
print(onelink.title())
</syntaxhighlight>
</source>
 
==Alle pagina's met een bepaald sjabloon erop==
<sourcesyntaxhighlight lang="python">
import pywikibot
from pywikibot import pagegenerators
Regel 139:
if mypage.namespace().id in allowed_namespaces:
print(mypage.title())
</syntaxhighlight>
</source>
 
 
==Wikidata-items bekijken==
<sourcesyntaxhighlight lang="python">
#import pywikibot
 
Regel 159:
for sl in wikidataitem.sitelinks: #alle talen en de link naar het artikel in die taal
print('%s : %s' % (sl, wikidataitem.sitelinks[sl]))
</syntaxhighlight>
</source>
 
==Wikidata-property ophalen==
<sourcesyntaxhighlight lang="python">
#import pywikibot
site=pywikibot.Site('nl')
Regel 168:
wditem=pywikibot.ItemPage(repo,'Q2013')
otheritem=wditem.claims.get('P31')[0].getTarget() # gets value of the first P31 value defined on Q2013
</syntaxhighlight>
</source>
 
==Wikidata:SparQL query==
<sourcesyntaxhighlight lang="python">
import pywikibot
import from pywikibot pagegenerators as pg
Regel 193:
print('%s - %s' % (i,person.title()))
action_one_item(person)
</syntaxhighlight>
</source>
 
==Ophalen wikidata bij pagina==
<sourcesyntaxhighlight lang="python">
import pywikibot
 
Regel 207:
pass #no wikidata for this page
 
</syntaxhighlight>
</source>
 
<!-- ----- Hieronder onderhoudsmeldingen, niet verwijderen ----- -->
{{subSub}}
Informatie afkomstig van https://nl.wikibooks.org Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.