Jump to content

User:Firefly/code/insertat

From Wikipedia, the free encyclopedia

<source lang=python>

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-

import wikipedia

  1. Inserts text directly before interlanguage links/categories if they exist, else it appends the text to the end of the article

def endofprose(pagetext, addition):

   site = wikipedia.getSite()
   interwiki  =  wikipedia.getLanguageLinks(pagetext, site)
   categories =  wikipedia.getCategoryLinks(pagetext, site)
   pagetext   =  wikipedia.removeLanguageLinks(pagetext, site)
   pagetext   =  wikipedia.removeCategoryLinks(pagetext, site)
   pagetext   += '\n\n' + addition
   pagetext   =  wikipedia.replaceLanguageLinks(pagetext,interwiki)
   pagetext   =  wikipedia.replaceCategoryLinks(pagetext,categories)
   return pagetext