niktrans

NikTrans

Python script to create Nikola sites from a list of schools. Edits conf.py file for site name and licence.

In [5]:
import os
import json
In [ ]:
os.system('python3 nikoladu.py')
os.chdir('/home/wcmckee/nik1/')
os.system('nikola build')
os.system('rsync -azP /home/wcmckee/nik1/* wcmckee@wcmckee.com:/home/wcmckee/github/wcmckee.com/output/minedujobs')
In [6]:
opccschho = open('/home/wcmckee/ccschool/cctru.json', 'r')
In [7]:
opcz = opccschho.read()
In [8]:
rssch = json.loads(opcz)
In [9]:
filrma = ('/home/wcmckee/ccschol/')
In [10]:
for rs in rssch.keys():
    hythsc = (rs.replace(' ', '-'))
    hylow = hythsc.lower()
    hybrac = hylow.replace('(', '')
    hybaec = hybrac.replace(')', '')
    os.mkdir(filrma + hybaec)
    
    os.system('nikola init -q ' + filrma + hybaec)
    

I want to open each of the conf.py files and replace the nanme of the site with hythsc.lower

Dir /home/wcmckee/ccschol has all the schools folders. Need to replace in conf.py Demo Name with folder name of school.

Schools name missing characters - eg ardmore

In [11]:
lisschol = os.listdir('/home/wcmckee/ccschol/')
In [12]:
findwat = ('LICENSE = """')
In [13]:
def replacetext(findtext, replacetext):
    for lisol in lisschol:
        filereaz = ('/home/wcmckee/ccschol/' + hybaec + '/conf.py')
        f = open(filereaz,'r')
        filedata = f.read()
        f.close()

        newdata = filedata.replace(findtext, '"' + replacetext + '"')
        #print (newdata)
        f = open(filereaz,'w')
        f.write(newdata)
        f.close()
In [14]:
replacetext('LICENSE = """', 'LICENSE = """<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons Attribution 4.0 International License" style="border-width:0; margin-bottom:12px;" src="https://i.creativecommons.org/l/by/4.0/88x31.png"></a>"')
In [15]:
licfil = 'LICENSE = """<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons Attribution 4.0 International License" style="border-width:0; margin-bottom:12px;" src="https://i.creativecommons.org/l/by/4.0/88x31.png"></a>"'
In [16]:
opwcm = ('/home/wcmckee/github/wcm.com/conf.py')
In [17]:
for lisol in lisschol:
    print (lisol)
    rdwcm = open(opwcm, 'r')
    
    filewcm = rdwcm.read()
    newdata = filewcm.replace('wcmckee', lisol)

    rdwcm.close()
    #print (newdata)
    
    f = open('/home/wcmckee/ccschol/' + lisol + '/conf.py','w')
    f.write(newdata)
    f.close()
te-wharekura-o-maniapoto
ardmore
shotover-school
hobsonville-point-secondary-school
south-hornby
thorndon
leigh-school
st-josephs-upper-hutt
green-bay
oaklands-
hampden-street
rangiora-borough
pegasus-bay
te-pa-o-rakaihautu
paparoa-street
te-one
kaikohe-west
thorrington
grey-lynn
ohoka
westlake-girls-high-school
merrin
stonefields-school
sylvia-park-school
roydvale
marlborough-primary
ward
raphael-house
whau-valley
taipa-area-school-
pukekohe-intermediate
ashburton-intermediate
onewhero-area
rawhiti
horowhenua-college
our-lady-star-of-the-sea-sumner
taradale-intermediate
eastern-hutt
st-marys-catholic-tauranga
windwhistle
northcote-college
diamond-harbour
barton-rural
orewa-college
ebbett-park
shirley-intermediate
sumner
arrowtown
taupaki-school
yaldhurst-model
nelson-park
wellington-high-school
redwood-tawa
somerfield
marewa
albany-senior-high-school
middleton-grange-school
kaingaroa-chatham-islands
cheviot-area
okaihau-college
runanga
hutt-valley-high-school
our-lady-of-victoriea
burnside-high-school
hillpark
tkkm-o-te-atihaunui-a-paparangi
tawa-intermediate
auckland-girls-grammar-school
broadfield
westmere
kaikoura-suburban
whangaparaoa-college
our-lady-of-snows-methven
waikato-diocesan
warrington-school
banks-avenue
cobham-intermediate
st-patrick’s-bryndwr
hobsonville-point-primary-school
te-hihi
st-patrick’s-kaiapoi
springston-school
nayland-college
elmwood-normal
pakuranga-heights-school
sacred-heart-catholic
eskdale
In [18]:
for rdlin in rdwcm.readlines():
    #print (rdlin)
    if 'BLOG_TITLE' in rdlin:
        print (rdlin)
        
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-46372e43ced8> in <module>()
----> 1 for rdlin in rdwcm.readlines():
      2     #print (rdlin)
      3     if 'BLOG_TITLE' in rdlin:
      4         print (rdlin)
      5 

ValueError: I/O operation on closed file.
In [ ]:
for lisol in lisschol:
    print (lisol)
    hythsc = (lisol.replace(' ', '-'))
    hylow = hythsc.lower()
    hybrac = hylow.replace('(', '')
    hybaec = hybrac.replace(')', '')
    filereaz = ('/home/wcmckee/ccschol/' + hybaec + '/conf.py')
    f = open(filereaz,'r')
    filedata = f.read()
    f.close()

    newdata = filedata.replace('LICENCE = """', licfil )
    #print (newdata)
    f = open(filereaz,'w')
    f.write(newdata)
    f.close()
In [ ]:
for lisol in lisschol:
    print (lisol)
    hythsc = (lisol.replace(' ', '-'))
    hylow = hythsc.lower()
    hybrac = hylow.replace('(', '')
    hybaec = hybrac.replace(')', '')
    filereaz = ('/home/wcmckee/ccschol/' + hybaec + '/conf.py')
    f = open(filereaz,'r')
    filedata = f.read()
    f.close()

    newdata = filedata.replace('"Demo Site"', '"' + hybaec + '"')
    #print (newdata)
    f = open(filereaz,'w')
    f.write(newdata)
    f.close()
In [ ]:
for lisol in lisschol:
    print (lisol)
    hythsc = (lisol.replace(' ', '-'))
    hylow = hythsc.lower()
    hybrac = hylow.replace('(', '')
    hybaec = hybrac.replace(')', '')
    filereaz = ('/home/wcmckee/ccschol/' + hybaec + '/conf.py')
    f = open(filereaz,'r')
    filedata = f.read()
    f.close()

    newdata = filedata.replace('"Demo Site"', '"' + hybaec + '"')
    #print (newdata)
    f = open(filereaz,'w')
    f.write(newdata)
    f.close()

Perform Nikola build of all the sites in ccschol folder

In [ ]:
buildnik = input('Build school sites y/N ')
In [ ]:
for lisol in lisschol:
    print (lisol)
    os.chdir('/home/wcmckee/ccschol/' + lisol)
    if 'y' in buildnik:
        os.system('nikola build')
In [ ]:
makerst = open('/home/wcmckee/ccs')
In [ ]:
for rs in rssch.keys():
    hythsc = (rs.replace(' ', '-'))
    hylow = hythsc.lower()
    hybrac = hylow.replace('(', '-')
    hybaec = hybrac.replace(')', '')
    
    #print (hylow())
    filereaz = ('/home/wcmckee/ccschol/' + hybaec + '/conf.py')
    f = open(filereaz,'r')
    filedata = f.read()
    

    newdata = filedata.replace("Demo Site", hybaec)
    f.close()
    f = open(filereaz,'w')
    f.write(newdata)
    f.close()

Comments

Comments powered by Disqus