designer_gen.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/python3
  2. import os
  3. import codecs
  4. import dataset
  5. def extract_comp(fname):
  6. resultstr=""
  7. fr=codecs.open(fname,'r','utf-8')
  8. lines=fr.readlines()
  9. inloop=False
  10. for l in lines:
  11. if inloop:
  12. if '<script async defer crossorigin="anonymous" src="https://connect.facebook' in l:
  13. # break
  14. #<script async="" defer="" crossorigin="anonymous" src="https://connect.facebook.net/zh_TW/sdk.js#xfbml=1&amp;version=v9.0" nonce=""></script>
  15. # if '/article>' in l:
  16. # resultstr+=l
  17. break
  18. resultstr+=l+"\n"
  19. # if 'class="dAbout"' in l and 'article' in l:
  20. if 'row justify-content-between mt-5' in l:
  21. inloop=True
  22. resultstr+=l+"\n"
  23. continue
  24. return resultstr
  25. #<script async defer crossorigin="anonymous" src="https://connect.facebook.net/
  26. def proc_file(fname,fname2,compcontent):
  27. fr=codecs.open(fname,'r','utf-8')
  28. fw=codecs.open(fname2,'w','utf-8')
  29. lines=fr.readlines()
  30. scriptflag=False
  31. for l in lines:
  32. # <div class="row mt-5" id="row">
  33. if 'div' in l and 'class' in l and 'row mt-5' in l and 'id="row"' in l:
  34. fw.write('<div class="row mt-5" id="row_company" style="display:none">\n')
  35. fw.write(compcontent)
  36. fw.write('</div>\n')
  37. fw.write('<div class="row mt-5" id="row_intro">\n')
  38. if 'likeSee__state__filter' in l and 'likeSee__state__filter--offset'in l:
  39. fw.write('<div class="likeSee__state__filter likeSee__state__filter--offset" id="id_offs">')
  40. continue
  41. if 'nav-link' in l and '設計師作品' in l and 'class' in l:
  42. if 'active' in l:
  43. fw.write('<a href="#" class="nav-link active" onclick="c_intro();" id="a_intro">設計師作品</a>')
  44. else:
  45. fw.write('<a href="#" class="nav-link " onclick="c_intro();" id="a_intro">設計師作品</a>')
  46. continue
  47. if 'nav-link' in l and '設計師公司簡介' in l and 'class' in l:
  48. if 'active' in l:
  49. fw.write('<a href="#" class="nav-link active" onclick="c_comp();" id="a_company">設計師公司簡介</a>')
  50. else:
  51. fw.write('<a href="#" class="nav-link " onclick="c_comp();" id="a_company">設計師公司簡介</a>')
  52. continue
  53. fw.write(l)
  54. if '</script>' in l and not scriptflag:
  55. scriptflag=True
  56. fw.write('\n <script async defer crossorigin="anonymous" src="https://connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v9.0" nonce="7TsDzQN7"></script> \n')
  57. fw.write("\n <script>")
  58. fw.write("function c_intro(){ \n")
  59. fw.write("var rintro= document.getElementById('row_intro'); \n")
  60. fw.write("var rcomp = document.getElementById('row_company'); \n")
  61. fw.write("var aintro = document.getElementById('a_intro'); \n")
  62. fw.write("var id_offs = document.getElementById('id_offs'); \n")
  63. fw.write(' id_offs.style.display="block"; \n')
  64. fw.write(' rintro.style.display="block"; \n')
  65. fw.write(' rcomp.style.display = "none"; \n')
  66. fw.write(' aintro.className = "nav-link active"; \n')
  67. fw.write("} \n")
  68. fw.write("function c_comp(){ \n")
  69. fw.write("var rintro= document.getElementById('row_intro'); \n")
  70. fw.write("var rcomp = document.getElementById('row_company'); \n")
  71. fw.write("var aintro = document.getElementById('a_company'); \n")
  72. fw.write("var id_offs = document.getElementById('id_offs'); \n")
  73. fw.write(' id_offs.style.display="none"; \n')
  74. fw.write(' rcomp.style.display = "block"; \n')
  75. fw.write(' rintro.style.display="none"; \n')
  76. fw.write(' aintro.className = "nav-link active"; \n')
  77. fw.write("} </script> \n")
  78. #
  79. # print(lines)
  80. fr.close()
  81. fw.close()
  82. db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57-cluster.cluster-cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4')
  83. dir_prefix='/var/www/jared-six/'
  84. cursor=db.query('SELECT hdesigner_id FROM xoops._hdesigner where onoff=1; ')
  85. for c in cursor:
  86. did=c['hdesigner_id']
  87. # if did != 23:
  88. # continue
  89. print(did)
  90. curdir=dir_prefix+str(did)
  91. if not os.path.exists(curdir):
  92. os.mkdir(curdir)
  93. os.chdir(curdir)
  94. os.system('curl https://hhh.com.tw/designers/cases/'+str(did)+'/1-page/new-sort/ -o orig.html')
  95. os.system('curl https://hhh.com.tw/designers/details/'+str(did)+'/ -o comp.html')
  96. result=extract_comp(curdir+"/comp.html")
  97. print(result)
  98. proc_file(curdir+"/orig.html",curdir+"/index.html",result)
  99. # break
  100. #for l in lst:
  101. # os.chdir(curdir)
  102. # os.system('curl https://hhh.com.tw/columns/detail/'+l+'/ > index.html')