NikTrans

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


In [ ]:
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 [ ]:
opccschho = open('/home/wcmckee/ccschool/cctru.json', 'r')

In [ ]:
opcz = opccschho.read()

In [ ]:
rssch = json.loads(opcz)

In [ ]:
filrma = ('/home/wcmckee/ccschol/')

In [ ]:
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 [ ]:
lisschol = os.listdir('/home/wcmckee/ccschol/')

In [ ]:
findwat = ('LICENSE = """')

In [ ]:
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 [ ]:
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 [ ]:
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 [ ]:
opwcm = ('/home/wcmckee/github/wcm.com/conf.py')

In [ ]:
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()

In [ ]:
for rdlin in rdwcm.readlines():
    #print (rdlin)
    if 'BLOG_TITLE' in rdlin:
        print (rdlin)

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()