123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/usr/bin/python3
- import os
- import codecs
- import dataset
- db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57-cluster.cluster-cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4')
- #lst=['5926','5878','5912','5939','5885','4300','1042','3559']
- #lst=['3559']
- #lst=['5926','5878','5912','5939','5885','4300','1042']
- #lst=['5926','5878','5912','5939','5885','4300']
- #lst=['5926']
- ins_cmd=''
- dir_prefix='/var/www/jared-faq/'
- for l in lst:
- curdir=dir_prefix+l+'/index.html'
- outdir=dir_prefix+'modify/'+l+"/"
- # outfile='/tmp/out.html'
- if not os.path.exists(outdir):
- os.mkdir(outdir)
- outfile=outdir+'index.html'
- json_content=None
- cursor=db.query('select json_ld from xoops._hcolumn where hcolumn_id="'+l+'"')
- for c in cursor:
- json_content=c['json_ld']
- break
- jsonld='<script type="application/ld+json">[___TEMPLATE___]</script>'
- # curdir=dir_prefix+l+'/new.html'
- fr=codecs.open(curdir,'r','utf-8')
- lines=fr.readlines()
- fr.close()
- idx=0
- alldata=''
- skipmode=False
- for line in lines:
- if '<script type="application/ld+json">' in line:
- skipmode=True
- continue
- if skipmode and '</script>' in line:
- skipmode=False
- continue
- if skipmode:
- print('skip')
- continue
- if '<meta name="twitter:image"' in line:
- alldata+=line
- newjson=jsonld.replace('[___TEMPLATE___]',json_content)
- print(newjson)
- alldata+=newjson+"\n"
- print(l)
- else:
- alldata+=line
- # print(line)
- fw=codecs.open(outfile,'w','utf-8')
- fw.write(alldata)
- fw.close()
|