Last active
December 11, 2015 04:18
-
-
Save vssun/4543697 to your computer and use it in GitHub Desktop.
ജേക്കബ് തന്ന താളുകളെ വിക്കിനിഘണ്ടുവിൽ കയറ്റാനുണ്ടാക്കിയ ഒരു തല്ലിപ്പൊളി സ്ക്രിപ്റ്റ്
വിക്ഷണറിയിലെ ആവശ്യത്തിനു വേണ്ടി
ടെക്സ്റ്റ് ഫയലിലുള്ള നിർവചനങ്ങൾ ഒറ്റയടിക്ക് നിഘണ്ടുവിൽ ചേർക്കാൻ
നിർമ്മിച്ചത്: സുനിൽ വി.എസ്.
2013-01-13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
""" | |
വിക്ഷണറിയിലെ ആവശ്യത്തിനു വേണ്ടി | |
ടെക്സ്റ്റ് ഫയലിലുള്ള നിർവചനങ്ങൾ ഒറ്റയടിക്ക് നിഘണ്ടുവിൽ ചേർക്കാൻ | |
നിർമ്മിച്ചത്: സുനിൽ വി.എസ്. | |
2013-01-13 | |
""" | |
import wikipedia | |
import codecs | |
#പ്രധാന പ്രോഗ്രാം ഇവിടെ തുടങ്ങുന്നു. | |
#ആവശ്യത്തിനനുസരിച്ച് മാറ്റങ്ങൾ ഇതിനു താഴെ വരുത്തുക | |
siteFamily = 'wiktionary' | |
siteLangCode = 'ml' | |
dataFileName = "/home/vssun/data/o_source.txt" #നിർവചനങ്ങൾ ഏതു ഫയലിൽ? | |
errorFileName = "/home/vssun/data/errorfile.txt" #നിലവിൽ വിക്കിയിലുള്ള നിർവചനങ്ങളുടെ പട്ടിക, അതായത് ഇമ്പോർട്ട് ചെയ്യാത്തവ, ഓരോ റണ്ണിലും ഈ ഫയലിൽ കൂട്ടിച്ചേർക്കപ്പെടും | |
#ഡേറ്റാഫയലിൽ നിർവചനങ്ങൾ എങ്ങനെ ക്രമീകരിച്ചിരിക്കുന്നു എന്നത് താഴെ വിവരിച്ചിരിക്കുന്നു. | |
startDescriptor = '{{-start-}}<!--' #ഓരോ നിർവചനങ്ങളുടെയും തുടക്കം | |
startDescriptorEnd = '-->' #ആ വരിയുടെ അവസാനം | |
endDescriptor = '{{-stop-}}' #നിർവചനത്തിന്റെ അവസാനം | |
startPoint=u"Accidental" #പ്രവർത്തനം ഇനിയെവിടെത്തുടങ്ങണം? ഓരോ തവണ പ്രവർത്തിച്ചുതീരുമ്പോഴും ഇനി അടുത്ത താളേതാണ് വേണ്ടതെന്ന് സ്ക്രീനിൽ കാണിക്കും. | |
pageHeader = u"== ഇംഗ്ലീഷ് ==\n=== നാമം ===\n{{en-noun}}\n" #ഓരോ താളിന്റെയും മുകൾഭാഗത്ത് ചേർക്കേണ്ട ഉള്ളടക്കം | |
pageFooter = u"\n[[വർഗ്ഗം:ഇറക്കുമതി ചെയ്ത താളുകൾ]]" #ഓരോ താളിന്റെയും താഴെ ചേർക്കേണ്ട ഉള്ളടക്കം | |
editSummary= u"താളുകൾ വൻതോതിൽ ഇറക്കുമതി ചെയ്യുന്നു" #ഓരോ താളിന്റെയും താഴെ ചേർക്കേണ്ട ഉള്ളടക്കം | |
maxPageCount=100 #ഈ ഓട്ടത്തിൽ എത്ര താളുകൾ ഇറക്കുമതി ചെയ്യണം? | |
#ആവശ്യത്തിനനുസരിച്ച് മാറ്റങ്ങൾ ഇതിനു മുകളിൽ വരുത്തുക | |
myDataFile=codecs.open(dataFileName,encoding='utf-8') | |
myErrorFile=codecs.open(errorFileName,encoding='utf-8', mode='a') | |
wikiSite = wikipedia.Site(code=siteLangCode, fam=siteFamily) | |
myErrorText=ur'' | |
myPageCount=0 | |
for myLine in myDataFile: | |
#പ്രവർത്തനം തുടങ്ങേണ്ട വരിയിലേക്ക് എത്തിച്ചേരാനുള്ള കോഡ് താഴെ | |
if len(startPoint)>0: | |
myCheckString=startDescriptor+startPoint+startDescriptorEnd | |
if myLine[0:len(myCheckString)] == myCheckString: | |
startPoint=u"" | |
else: | |
continue | |
#ഓരോ നിർവചനത്തിന്റേയും തുടക്കത്തിലാണ് നിൽക്കുന്നതെങ്കിൽ താളിന്റെ പേരെടുക്കുകയും അതിലെ ഉള്ളടക്കം എടുത്ത് myContent എന്ന ചരത്തിൽ നിറക്കുന്ന ബ്ലോക്ക് | |
if myLine[0:len(startDescriptor)]==startDescriptor: | |
myPageName=myLine[len(startDescriptor):len(myLine)-len(startDescriptorEnd)-2] #താളിന്റെ പേരെടുക്കുന്നു | |
myPageNameOriginal=myPageName | |
#a xyz എന്ന രീതിയിലുള്ള നിർവചനത്തിൽ നിന്ന് a ഒഴിവാക്കാൻ | |
if myPageName[0:2]=="A ": | |
myPageName=myPageName[2:len(myPageName)] | |
myPageName=myPageName.lower() #താളിന്റെ പേരിലെ വലിയക്ഷരം ഒഴിവാക്കാൻ | |
wikipedia.output(myPageName) | |
#ഉള്ളടക്കം നിറക്കുന്ന ബ്ലോക്ക് | |
myContent=ur"" | |
while True: | |
myLine=myDataFile.readline() | |
if myLine[0:len(endDescriptor)]==endDescriptor: | |
break | |
else: | |
if myLine[0:3]=="#[[": | |
myLine=myLine.replace(" ", "]] [[") #ഉള്ളടക്കത്തിൽ ഓരോ വാക്കിനും കണ്ണി ചേർക്കാൻ | |
myContent=myContent+myLine | |
#സോഴ്സ്ഫയലിലെ ഉള്ളടക്കം ശൂന്യമായ നിർവചനങ്ങളെ ഒഴിവാക്കി മറ്റുള്ളവ മാത്രം വിക്കിയിലേക്കെഴുതാൻ | |
if len(myContent)>0: | |
myWikiPage = wikipedia.Page(site=wikiSite, title=myPageName) | |
#വിക്കിയിൽ താൾ നിലവിലുണ്ടെങ്കിൽ അക്കാരം errorFile-ലേക്കെഴുതാൻ വേണ്ടി ഉള്ളടക്കം തയാറാക്കുന്നു. അല്ലെങ്കിൽ വിക്കിയിലേക്കെഴുതുന്നു. | |
if myWikiPage.exists(): | |
myErrorText=myErrorText+myPageNameOriginal+"\n" | |
else: | |
myContent=myContent+"\n[[en:" + myPageName + "]]" #ഇംഗ്ലീഷ് വിക്കി കണ്ണി | |
myWikiPage.put(pageHeader+myContent+pageFooter, comment=editSummary) | |
myPageCount=myPageCount+1 | |
wikipedia.output(myContent) | |
# മുകളിൽ പറഞ്ഞത്രയും താളുകൾ ചേർത്ത് പ്രവർത്തനം നിർത്തുന്നു. | |
if myPageCount>=maxPageCount: | |
wikipedia.output("Next to run: " + myDataFile.readline()) #ഇനി എവിടെത്തുടങ്ങാം എന്ന് സ്ക്രീനിൽ കാണിക്കുന്നു. | |
break | |
myErrorFile.write(myErrorText) | |
myErrorFile.close() | |
myDataFile.close() | |
wikipedia.stopme() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment