Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vssun
Created August 24, 2012 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vssun/3453817 to your computer and use it in GitHub Desktop.
Save vssun/3453817 to your computer and use it in GitHub Desktop.
തിയതി താളുകൾ ചരിത്രരേഖയിൽ ശരിയായി വരാനുള്ള റീപ്ലേസ്മെന്റ് കോഡ് - വിക്കിപീഡിയ
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
തിയതി താളുകൾ ചരിത്രരേഖയിൽ ശരിയായി വരാനുള്ള റീപ്ലേസ്മെന്റ് കോഡ്
നിർമ്മിച്ചത്: സുനിൽ വി.എസ്.
തിയതി: 2012-08-24
"""
import wikipedia
import pagegenerators
import catlib
#പ്രധാന പ്രോഗ്രാം ഇവിടെ തുടങ്ങുന്നു.
#ആവശ്യത്തിനനുസരിച്ച് മാറ്റങ്ങൾ ഇതിനു താഴെ വരുത്തുക
siteFamily = 'wikipedia'
siteLangCode = 'ml'
textFileName ='pagelist.txt' #വർഗ്ഗം താറുമാറായതിനാൽ തിയതി താളുകളുടെ പട്ടികയുണ്ടാക്കി ഈ ഫയലിലിട്ടു
findText1 =ur"==" + "\n</noinclude>"
replaceText1 =ur"==" + "\n<onlyinclude>"
findText2 ="<noinclude>\n" + ur"=="
findText21 ="<noinclude>\n\n" + ur"=="
replaceText2 ="</onlyinclude>\n" + ur"=="
replaceText2 ="</onlyinclude>\n" + ur"=="
findText3 =ur"<noinclude>"
findText4 =ur"</noinclude>"
errorPage =ur'user:vssun/test'
#ആവശ്യത്തിനനുസരിച്ച് മാറ്റങ്ങൾ ഇതിനു മുകളിൽ വരുത്തുക
wikiSite = wikipedia.Site(code=siteLangCode, fam=siteFamily)
myErrorPage = wikipedia.Page(site=wikiSite,title=errorPage)
myErrorText=""
for myPage in pagegenerators.TextfilePageGenerator(filename=textFileName):
wikipedia.output("Working on " + myPage.title())
myText=myPage.get()
if myText.count("<noinclude>")>0:
if myText.count(findText1)>0 and (myText.count(findText2)>0 or myText.count(findText21)>0):
myText=myText.replace(findText1,replaceText1)
myText=myText.replace(findText2,replaceText2)
myText=myText.replace(findText21,replaceText2)
myText=myText.replace(findText3,"")
myText=myText.replace(findText4,"")
myPage.put(myText)
else:
myErrorText=myErrorText + "\n[[" + myPage.title() + "]]"
wikipedia.output("Errors:" + myErrorText)
myErrorPage.put(myErrorText)
wikipedia.stopme()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment