Skip to content

Instantly share code, notes, and snippets.

@vssun
Created November 14, 2011 18:03
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/1364623 to your computer and use it in GitHub Desktop.
Save vssun/1364623 to your computer and use it in GitHub Desktop.
ടെക്സ്റ്റ് ഫയലുകളിലായി കിട്ടുന്ന ഉള്ളടക്കം എല്ലാമെടുത്ത് പേജുകളിൽ നിറക്കാൻ. പ്രത്യേകിച്ച് കൈപ്പള്ളിയുടെ ബൈബിൾ ഗ്രന്ഥശാലയിലേക്കെത്തിക്കുക എന്ന ലക്ഷ്യത്തിൽ ഉണ്ടാക്കിയത് (വിക്കിഗ്രന്ഥശാല)
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
ഫയലുകളിലെ ഉള്ളടക്കം മൊത്തത്തിൽ ഗ്രന്ഥശാലയിലേക്കെത്തിക്കാൻ - പ്രത്യേകിച്ച് കൈപ്പള്ളിയുടെ ബൈബിൾ പകർത്താനുണ്ടാക്കിയത്
നിർമ്മിച്ചത്: സുനിൽ വി.എസ്.
തിയതി: 2011-11-14
ഫയലുകൾ 1:1.txt, 1:2.txt .. 2:1.txt .. എന്ന ക്രമത്തിൽ ലഭിക്കുമെന്ന് പ്രതീക്ഷിക്കുന്നു.
"""
import wikipedia
import codecs
#പ്രധാന പ്രോഗ്രാം ഇവിടെ തുടങ്ങുന്നു. ആവശ്യത്തിനനുസരിച്ച് മാറ്റങ്ങൾ ഇതിനു താഴെ വരുത്തുക
siteFamily = 'wikisource' #ഗ്രന്ഥശാല
siteLangCode = 'ml' #മലയാളം
wikiSite = wikipedia.Site(code=siteLangCode, fam=siteFamily)
maxChapters =3 #എത്ര അദ്ധ്യായങ്ങൾ വരെ പോകും?
dataSource ="/home/vssun/py/datasource" #ഫയലുകൾ എവിടെ വച്ചിരിക്കുന്നു?
outputPage ="user:Vssun/test" #താളുകൾ, വിക്കിയിൽ ഏതു താളിന്റെ ഉപതാളുകളായാണ് സൃഷ്ടിക്കേണ്ടത്?
#ആവശ്യത്തിനനുസരിച്ച് മാറ്റങ്ങൾ ഇതിനു മുകളീൽ വരുത്തുക
for i in range(1, maxChapters+1):
for j in range(1, maxChapters+1):
myFileName=dataSource+"/"+str(i)+":"+str(j)+".txt"
wikipedia.output("Trying to read from " + myFileName)
try:
fin=codecs.open(myFileName,encoding = 'utf-8')
myText=fin.read()
fin.close()
myOutputPage = wikipedia.Page(site=wikiSite,title=outputPage+"/"+str(i)+"/"+str(j))
wikipedia.output("Writing to " + myOutputPage.title())
myOutputPage.put(myText)
except IOError:
print "File does not exist!"
break
wikipedia.stopme()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment