Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:pywikibot [2025/02/09 06:20] darrontools:pywikibot [2025/02/11 02:42] (current) – [Examples] darron
Line 1: Line 1:
-[[https://doc.wikimedia.org/pywikibot/stable/|Pywikibot documentation]]+====Pywikibot====
  
-[[https://github.com/wikimedia/pywikibot|Pywikibot github]]+Wikimedia automation scripts.
  
 +===Clone===
  
-===Fetch=== 
 <code> <code>
 git clone --recursive https://github.com/wikimedia/pywikibot git clone --recursive https://github.com/wikimedia/pywikibot
 +</code>
 +
 +Perform all future operations inside the pywikibot repository directory.
 +
 +<code>
 cd pywikibot cd pywikibot
 </code> </code>
  
 ===Install=== ===Install===
 +
 <code> <code>
 python3 -m venv ~/.venvs/pywikibot python3 -m venv ~/.venvs/pywikibot
Line 16: Line 22:
 </code> </code>
  
-===Run===+===Config===
  
-Perform this operation inside the pywikibot repository directory.+First create a family file. 
 + 
 +<code> 
 +~/.venvs/pywikibot/bin/python pwb.py generate_family_file.py 
 +</code> 
 + 
 +Enter the URL and name to create a family file for the private site. 
 +Select no when asked about interwiki links.  
 + 
 +Eg. 
 +<code> 
 +from pywikibot import family 
 + 
 +class Family(family.Family):  # noqa: D101 
 +    name = 'MySite' 
 +    langs = { 
 +        'en': 'www.example.com', 
 +    } 
 + 
 +    def version(self, code): 
 +        return "1.4.3"  # The MediaWiki version used. 
 + 
 +    def scriptpath(self, code): 
 +        return { 
 +            'en': '/w', 
 +        }[code] 
 + 
 +    def protocol(self, code): 
 +        return { 
 +            'en': 'https', 
 +        }[code] 
 +</code> 
 + 
 +Next a user configuration is needed. 
 +<code> 
 +cp user-config.py.sample user-config.py 
 +vi user-config.py 
 +</code> 
 + 
 +Eg. 
 +<code> 
 +mylang = 'en' 
 +family = 'MySite' 
 +usernames['MySite']['en'] = 'Mybot' 
 +</code> 
 + 
 +Lastly run the login script to enter the password. 
 + 
 +<code> 
 +~/.venvs/pywikibot/bin/python pwb.py login -v -v 
 +</code> 
 + 
 +===Examples===
  
 <code> <code>
 ~/.venvs/pywikibot/bin/python pwb.py <script_name> ~/.venvs/pywikibot/bin/python pwb.py <script_name>
 </code> </code>
 +
 +<code>
 +source ~/.venvs/pywikibot/bin/activate.csh
 +./pwb.py welcome.py
 +deactivate
 +</code>
 +===Resources====
 +
 +[[https://github.com/wikimedia/pywikibot|Github]]|
 +
 +[[https://doc.wikimedia.org/pywikibot/stable/|Documentation]]
 +
 +[[https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis|Third party wikis]]
 +
 +[[https://www.mediawiki.org/wiki/Manual:Pywikibot/Wikidata|Wikidata]]