gen_data_index.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. import os
  2. from typing import Optional
  3. from dataset.util import ResultIter
  4. from datetime import tzinfo
  5. import datetime
  6. import mysql.connector
  7. from mysql.connector import Error
  8. import dataset
  9. import json
  10. from pytube import extract
  11. import requests
  12. access_token = "57e1d6642904ecc2348b2768b028b5dd74720f791c7a3fd7ec551db3fd12a303"
  13. hhhMBPath = '../hhh-home-mb'
  14. hhhPCPath = '../hhh-home-pc'
  15. #connstr = 'mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4'
  16. #2022/12/13 change
  17. connstr = 'mysql://hhh7796hhh:lYmWsu^ujcA1@ec2-3-35-26-49.ap-northeast-2.compute.amazonaws.com:3306/xoops?charset=utf8mb4'
  18. """ db = dataset.connect(
  19. 'mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4') """
  20. # charset='utf8',
  21. # collation='utf8_unicode_ci'
  22. #2022/12/13 change
  23. connobj = {
  24. 'host': 'ec2-3-35-26-49.ap-northeast-2.compute.amazonaws.com',
  25. 'database': 'xoops',
  26. 'user': 'hhh7796hhh',
  27. 'password': 'lYmWsu^ujcA1',
  28. 'use_unicode': True
  29. #'charset': 'utf8',
  30. #'collation': 'utf8_unicode_ci'
  31. }
  32. #connobj = {
  33. # 'host': 'hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com',
  34. # 'database': 'xoops',
  35. # 'user': 'hhh7796hhh',
  36. # 'password': 'lYmWsu^ujcA1',
  37. # 'use_unicode': True
  38. # #'charset': 'utf8',
  39. # #'collation': 'utf8_unicode_ci'
  40. #}
  41. def ExecuteQuery(isql):
  42. with mysql.connector.connect(**connobj) as connection :
  43. with connection.cursor(dictionary=True) as cursor:
  44. # connection.set_charset_collation('utf8','utf8_general_ci')
  45. #cursor = connection.cursor(dictionary=True)
  46. cursor.execute(isql)
  47. return cursor.fetchall()
  48. # def genjson_new(filename: str = "realtime.json"):
  49. # jData = json.load(open('../json/'+filename, encoding='utf8'))
  50. # records = ExecuteQuery("SELECT * FROM _had where (now() between start_time and end_time or ( start_time is null and end_time is null) or ( start_time = '0000-00-00 00:00:00' and end_time = '0000-00-00 00:00:00')) and onoff='1' and adtype like '首八大%' ")
  51. # for x in jData:
  52. # # 頂部輪播區-新刊頭
  53. # if x['id'] == 0:
  54. # records = ExecuteQuery("""SELECT adid,alt_use,adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  55. # WHERE adtype LIKE '新刊頭%'
  56. # AND onoff='1'
  57. # AND(NOW() BETWEEN start_time AND end_time OR(start_time='0000-00-00 00:00:00' and end_time='0000-00-00 00:00:00') or (start_time is null and end_time is NULL))
  58. # ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  59. # x["data"] = []
  60. # for c in records:
  61. # a = {'imgUrl': c['mlo'], 'link': str(
  62. # c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp']),'id':c['adid'],'alt':str(c['alt_use'])}
  63. # x["data"].append(a)
  64. # # print(x["data"])
  65. # # 主要輪播區-首八大
  66. # if x['id'] == 1:
  67. # records = ExecuteQuery("""SELECT adid,alt_use,adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp,logo_icon,index_char_1,index_char_2_1,index_char_2_2,index_char_2_3 FROM _had
  68. # WHERE adtype LIKE '首八大%'
  69. # AND onoff='1'
  70. # AND(NOW() BETWEEN start_time AND end_time OR(start_time='0000-00-00 00:00:00' and end_time='0000-00-00 00:00:00') or (start_time is null and end_time is NULL))
  71. # ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  72. # x["data"] = []
  73. # for c in records:
  74. # if c['index_char_1']==None:
  75. # c['index_char_1']=''
  76. # if c['index_char_2_1']==None:
  77. # c['index_char_2_1']=''
  78. # if c['index_char_2_2']==None:
  79. # c['index_char_2_2']=''
  80. # if c['index_char_2_3']==None:
  81. # c['index_char_2_3']=''
  82. # a = {'imgUrl': c['mlo'], 'link': str(
  83. # c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp']),'logo_icon':str(c['logo_icon']),'index_char_1':str(c['index_char_1']),'index_char_2_1':str(c['index_char_2_1']),'index_char_2_2':str(c['index_char_2_2']),'index_char_2_3':str(c['index_char_2_3']),'id':c['adid'],'alt':str(c['alt_use'])}
  84. # x["data"].append(a)
  85. # # print(x["data"])
  86. # #tab區塊-最夯設計, 影音實錄, 專欄文章
  87. # if x['id'] == 6:
  88. # x["data"] = []
  89. # #過年後修改
  90. # a = {'tab': '編輯精選', 'data': []}
  91. # records_for_custom = ExecuteQuery("""SELECT hcolumn_id, ctitle,clogo,cdesc,_hcolumn.ctag
  92. # FROM homepage_set
  93. # LEFT JOIN _hcolumn ON mapping_id = hcolumn_id
  94. # WHERE outer_set=8
  95. # AND homepage_set.onoff='Y'
  96. # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  97. # ORDER BY inner_sort limit 8""")
  98. # #加入不重複id
  99. # id_use = []
  100. # for c in records_for_custom:
  101. # id_use.append(c['hcolumn_id'])
  102. # id_len = 8 - len(id_use)
  103. # # print(id_use)
  104. # str_id_use=''
  105. # for k in id_use:
  106. # str_id_use+=' and hcolumn_id!=%s '%k
  107. # # print(str_id_use)
  108. # #加入不重複id sql
  109. # # records = ExecuteQuery("""SELECT ctag,ctitle TT,clogo IMG, CONCAT('/columns/detail/',hcolumn_id,'/') LK, cdesc
  110. # # from _hcolumn
  111. # # WHERE onoff='1' """+str_id_use+"""
  112. # # AND NOW() > sdate
  113. # # ORDER BY hcolumn_id DESC
  114. # # LIMIT 8""")
  115. # records = ExecuteQuery("""SELECT ctag,ctitle TT,clogo IMG, CONCAT('/columns/detail/',hcolumn_id,'/') LK, cdesc
  116. # from _hcolumn
  117. # WHERE onoff='1' """ +str_id_use+"""
  118. # AND NOW() > sdate
  119. # ORDER BY sdate desc,hcolumn_id DESC
  120. # LIMIT """+ str(id_len) +""" """)
  121. # for d in records_for_custom:
  122. # ad = {'imgUrl': d['clogo'], 'link': "/columns/detail/" + str(
  123. # d['hcolumn_id']) + "/", 'title': d['ctitle'], 'ctag':d['ctag'].split(',')}
  124. # a["data"].append(ad)
  125. # for c in records:
  126. # ctag_list=c['ctag'].split(',')
  127. # if len(ctag_list)==1 and ctag_list[0]=='':
  128. # ctag_list=[]
  129. # ad = {'imgUrl': c['IMG'], 'link': c['LK'],
  130. # 'title': c['TT'],'ctag':ctag_list}
  131. # a['data'].append(ad)
  132. # x["data"].append(a)
  133. # a = {'tab': '最夯設計', 'data': []}
  134. # records_for_custom = ExecuteQuery(""" SELECT hcase_id,caption TT,tag ,cover IMG, CONCAT('/cases/detail/',hcase_id,'/') LK,_hdesigner.hdesigner_id hid,img_path,title
  135. # FROM homepage_set
  136. # LEFT JOIN _hcase ON mapping_id = hcase_id
  137. # left join _hdesigner ON _hcase.hdesigner_id=_hdesigner.hdesigner_id
  138. # WHERE outer_set=2 and _hcase.onoff='1' AND _hdesigner.onoff='1'
  139. # AND homepage_set.onoff='Y'
  140. # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  141. # ORDER BY inner_sort limit 8""")
  142. # #加入不重複id
  143. # id_use = []
  144. # for c in records_for_custom:
  145. # id_use.append(c['hcase_id'])
  146. # id_len = 8 - len(id_use)
  147. # # print(id_use)
  148. # str_id_use=''
  149. # for k in id_use:
  150. # str_id_use+=' and hcase_id!=%s '%k
  151. # records = ExecuteQuery("""SELECT hcase_id,caption TT,tag ,cover IMG, CONCAT('/cases/detail/',hcase_id,'/') LK,_hdesigner.hdesigner_id hid,img_path,title
  152. # from _hcase
  153. # left join _hdesigner ON _hcase.hdesigner_id=_hdesigner.hdesigner_id
  154. # WHERE
  155. # _hcase.onoff='1' AND _hdesigner.onoff='1'
  156. # AND (NOW() > sdate) """+str_id_use+"""
  157. # ORDER BY sdate desc,hcase_id DESC
  158. # LIMIT """+ str(id_len) +""" """)
  159. # count_k=1
  160. # for d in records_for_custom:
  161. # ctag_list="、".join(d['tag'].split(',')).split("、")
  162. # if len(ctag_list)==1 and ctag_list[0]=='':
  163. # ctag_list=[]
  164. # ad = {'imgUrl': d['IMG'], 'link': d['LK'],'img_designer':d['img_path'],
  165. # 'title': d['TT'],'ctag':ctag_list,'title_designer':d['title'],'link_designer': "/HHH_NEW/designers/index_designerList.php?cid=" + str(c['hid'])}
  166. # a["data"].append(ad)
  167. # for c in records:
  168. # # print(c['hcase_id'])
  169. # ctag_list="、".join(c['tag'].split(',')).split("、")
  170. # if len(ctag_list)==1 and ctag_list[0]=='':
  171. # ctag_list=[]
  172. # ad = {'imgUrl': c['IMG'], 'link': c['LK'],'img_designer':c['img_path'],
  173. # 'title': c['TT'],'ctag':ctag_list,'title_designer':c['title'],'link_designer': "/HHH_NEW/designers/index_designerList.php?cid=" + str(c['hid'])}
  174. # a['data'].append(ad)
  175. # x["data"].append(a)
  176. # a = {'tab': '最新影音實錄', 'data': []}
  177. # records_for_custom = ExecuteQuery(""" SELECT hvideo_id,title TT,iframe IMG , CONCAT('https://hhh.com.tw/video-post.php?id=',hvideo_id) LK , name
  178. # FROM homepage_set
  179. # LEFT JOIN _hvideo ON mapping_id = hvideo_id
  180. # WHERE outer_set=3
  181. # AND homepage_set.onoff='Y'
  182. # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR (homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  183. # ORDER BY inner_sort limit 8""")
  184. # #加入不重複id
  185. # id_use = []
  186. # for c in records_for_custom:
  187. # id_use.append(c['hvideo_id'])
  188. # id_len = 8 - len(id_use)
  189. # # print(id_use)
  190. # str_id_use=''
  191. # for k in id_use:
  192. # str_id_use+=' and hvideo_id!=%s '%k
  193. # records = ExecuteQuery("""SELECT title TT,iframe IMG , CONCAT('https://hhh.com.tw/video-post.php?id=',hvideo_id) LK , name
  194. # from _hvideo where display_datetime < NOW() """+str_id_use+""" and onoff=1
  195. # ORDER BY hvideo_id DESC
  196. # LIMIT """+ str(id_len) +""" """)
  197. # for d in records_for_custom:
  198. # tid = extract.video_id(d['IMG'])
  199. # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  200. # ad = {'imgUrl': timg, 'link': "https://www.youtube.com/watch?v="+str(tid),
  201. # 'description': d['TT']}
  202. # a["data"].append(ad)
  203. # for c in records:
  204. # tid = extract.video_id(c['IMG'])
  205. # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  206. # ad = {'imgUrl': timg, 'link': "https://www.youtube.com/watch?v="+str(tid),
  207. # 'description': c['TT']}
  208. # a['data'].append(ad)
  209. # x["data"].append(a)
  210. # # print(x["data"])
  211. # # 主題企劃區
  212. # if x['id'] == 4:
  213. # records = ExecuteQuery("""SELECT logo lo, CONCAT('/topic/detail/',htopic_id,'/') lk, `desc`, title FROM _htopic
  214. # WHERE onoff = '1'
  215. # ORDER BY htopic_id DESC limit 3""")
  216. # x["data"] = []
  217. # #手機板
  218. # a = {'tab': 'phone', 'data': []}
  219. # for c in records:
  220. # phone = {'imgUrl': c['lo'], 'link': str(
  221. # c['lk']), 'title': c['title']} #'video': 'false', 'description': c['desc'],
  222. # a["data"].append(phone)
  223. # x["data"].append(a)
  224. # #電腦版
  225. # records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  226. # IFNULL(ifnull(ifnull(_hcase.cover,_hcolumn.clogo),_hproduct.cover),_hbrand.logo) J,
  227. # (case when theme_type='case' then CONCAT('/cases/detail/d/',mapping_id) when theme_type='column' then CONCAT('/columns/detail/',mapping_id) when theme_type='product' then CONCAT('/product-post.php?id=',mapping_id) when theme_type='video' then CONCAT('https://hhh.com.tw/video-post.php?id=',mapping_id) when theme_type='brand' then CONCAT('/brand-index.php?brand_id=',mapping_id) ELSE '' END) url
  228. # FROM homepage_set left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  229. # LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'
  230. # LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'
  231. # LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  232. # LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  233. # WHERE homepage_set.onoff='Y' and outer_set=1 and (NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL)) order by inner_sort asc limit 4""")
  234. # a = {'tab': 'web', 'data': []}
  235. # for c in records:
  236. # phone = {'imgUrl': c['J'], 'link': str(
  237. # c['url']), 'title': c['caption']} #'video': 'false', 'description': c['desc'],
  238. # a["data"].append(phone)
  239. # x["data"].append(a)
  240. # # print(x["data"])
  241. # # 編輯精選
  242. # # if x['id'] == 4:
  243. # # records = ExecuteQuery("""SELECT hcolumn_id, ctitle, clogo,cdesc
  244. # # FROM homepage_set
  245. # # LEFT JOIN _hcolumn ON mapping_id = hcolumn_id
  246. # # WHERE outer_set=8
  247. # # AND homepage_set.onoff='Y'
  248. # # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  249. # # ORDER BY inner_sort""")
  250. # # x["data"] = []
  251. # # for c in records:
  252. # # a = {'imgUrl': c['clogo'], 'link': "https://hhh.com.tw/columns/detail/" + str(
  253. # # c['hcolumn_id']) + "/", 'title': c['ctitle'], 'video': 'false', 'description': c['cdesc']}
  254. # # x["data"].append(a)
  255. # # print(x["data"])
  256. # # 首列表廣告
  257. # if x['id'] == 3:
  258. # records = ExecuteQuery("""SELECT adid,alt_use,adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  259. # WHERE adtype LIKE '首列表廣告%'
  260. # AND onoff='1'
  261. # AND(NOW() BETWEEN start_time AND end_time OR(start_time='0000-00-00 00:00:00' and end_time='0000-00-00 00:00:00') or (start_time is null and end_time is NULL))
  262. # ORDER BY adtype""")
  263. # x["data"] = []
  264. # for c in records:
  265. # a = {'imgUrl': c['mlo'], 'link': str(
  266. # c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp']),'id':c['adid'],'alt':c['alt_use']}
  267. # x["data"].append(a)
  268. # # print(x["data"])
  269. # # 來選好物區
  270. # # if x['id'] == 6:
  271. # # records = ExecuteQuery(
  272. # # "SELECT max_row from outer_site_set WHERE title='來選好貨'")
  273. # # maxrow = 1
  274. # # for c in records:
  275. # # maxrow = c['max_row']
  276. # # records = ExecuteQuery("""(SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title) COLLATE utf8_general_ci caption , IFNULL(ifnull(_hcase.cover,_hcolumn.clogo),_hproduct.cover) COLLATE utf8_general_ci J, iframe , IFNULL(ifnull(ifnull(_hcase.short_desc,_hcolumn.cdesc),_hproduct.descr),_hvideo.`desc`) COLLATE utf8_general_ci short_desc
  277. # # , (case when theme_type='case' then CONCAT('https://hhh.com.tw/cases/detail/d/',mapping_id) when theme_type='column' then CONCAT('https://hhh.com.tw/columns/detail/',mapping_id) when theme_type='product' then CONCAT('https://hhh.com.tw/product-post.php?id=',mapping_id) when theme_type='video' then CONCAT('https://hhh.com.tw/video-post.php?id=',mapping_id) ELSE '' END) url
  278. # # -- SELECT *
  279. # # FROM homepage_set
  280. # # left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  281. # # LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  282. # # LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  283. # # LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  284. # # WHERE homepage_set.onoff='Y'
  285. # # AND outer_set = (SELECT oss_id from outer_site_set WHERE title='來選好貨')
  286. # # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  287. # # ORDER BY outer_set, inner_sort)
  288. # # UNION
  289. # # (SELECT 'product', id, `name`, cover, NULL ,descr ,CONCAT('https://hhh.com.tw/product-post.php?id=',id) FROM _hproduct WHERE onoff='1' ORDER BY id DESC LIMIT """ + str(maxrow) + """)
  290. # # LIMIT """ + str(maxrow))
  291. # # x["data"] = []
  292. # # for c in records:
  293. # # #print(c)
  294. # # if c['iframe'] is None:
  295. # # if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  296. # # c['J'] = c['J'].decode('utf8')
  297. # # if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  298. # # c['caption'] = c['caption'].decode('utf8')
  299. # # if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  300. # # c['short_desc'] = c['short_desc'].decode('utf8')
  301. # # a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  302. # # 'description': c['short_desc'], 'video': 'false'}
  303. # # else:
  304. # # tid = extract.video_id(str(c['iframe']))
  305. # # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  306. # # ccaption = ""
  307. # # cdescription = ""
  308. # # if isinstance(c['caption'], bytearray):
  309. # # ccaption = str(c['caption'].decode('utf8'))
  310. # # else:
  311. # # ccaption = str(c['caption'])
  312. # # if c['short_desc'] is not None:
  313. # # if isinstance(c['short_desc'], bytes):
  314. # # cdescription = str(c['short_desc'].decode('utf8'))
  315. # # else:
  316. # # cdescription = str(c['short_desc'])
  317. # # a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  318. # # 'description': cdescription, 'video': tid}
  319. # # x["data"].append(a)
  320. # # # print(x["data"])
  321. # # # 本週推薦
  322. # # if x['id'] == 7:
  323. # # # records = ExecuteQuery(
  324. # # # "SELECT max_row from outer_site_set WHERE title='本週推薦'")
  325. # # maxrow = 8
  326. # # # for c in records:
  327. # # # maxrow = c['max_row']
  328. # # records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  329. # # IFNULL(ifnull(ifnull(_hcase.cover,_hcolumn.clogo),_hproduct.cover),_hbrand.logo) J, iframe , IFNULL(ifnull(ifnull(ifnull(_hcase.short_desc,_hcolumn.cdesc),_hproduct.descr),_hvideo.`desc`),_hbrand.intro) short_desc
  330. # # , (case when theme_type='case' then CONCAT('https://hhh.com.tw/cases/detail/d/',mapping_id) when theme_type='column' then CONCAT('https://hhh.com.tw/columns/detail/',mapping_id) when theme_type='product' then CONCAT('https://hhh.com.tw/product-post.php?id=',mapping_id) when theme_type='video' then CONCAT('https://hhh.com.tw/video-post.php?id=',mapping_id) when theme_type='brand' then CONCAT('https://hhh.com.tw/brand-index.php?brand_id=',mapping_id) ELSE '' END) url
  331. # # -- SELECT *
  332. # # FROM homepage_set
  333. # # left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  334. # # LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  335. # # LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  336. # # LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  337. # # LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  338. # # WHERE homepage_set.onoff='Y'
  339. # # AND outer_set = (SELECT oss_id from outer_site_set WHERE title='本週推薦')
  340. # # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  341. # # ORDER BY outer_set, inner_sort
  342. # # LIMIT """ + str(maxrow))
  343. # # x["data"] = []
  344. # # for c in records:
  345. # # if c['iframe'] is None:
  346. # # if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  347. # # c['J'] = c['J'].decode('utf8')
  348. # # if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  349. # # c['caption'] = c['caption'].decode('utf8')
  350. # # if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  351. # # c['short_desc'] = c['short_desc'].decode('utf8')
  352. # # a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  353. # # 'description': c['short_desc'], 'video': 'false'}
  354. # # else:
  355. # # tid = extract.video_id(str(c['iframe']))
  356. # # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  357. # # ccaption = ""
  358. # # cdescription = ""
  359. # # if isinstance(c['caption'], bytearray):
  360. # # ccaption = str(c['caption'].decode('utf8'))
  361. # # else:
  362. # # ccaption = str(c['caption'])
  363. # # if c['short_desc'] is not None:
  364. # # if isinstance(c['short_desc'], bytes):
  365. # # cdescription = str(c['short_desc'].decode('utf8'))
  366. # # else:
  367. # # cdescription = str(c['short_desc'])
  368. # # a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  369. # # 'description': cdescription, 'video': tid}
  370. # # x["data"].append(a)
  371. # # # print(x["data"])
  372. # # # 粉絲推薦
  373. # # if x['id'] == 8:
  374. # # records = ExecuteQuery(
  375. # # "SELECT max_row from outer_site_set WHERE title='粉絲推薦'")
  376. # # maxrow = 1
  377. # # for c in records:
  378. # # maxrow = c['max_row']
  379. # # records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  380. # # IFNULL(ifnull(ifnull(_hcase.cover,_hcolumn.clogo),_hproduct.cover),_hbrand.logo) J, iframe , IFNULL(ifnull(ifnull(ifnull(_hcase.short_desc,_hcolumn.cdesc),_hproduct.descr),_hvideo.`desc`),_hbrand.intro) short_desc
  381. # # , (case when theme_type='case' then CONCAT('https://hhh.com.tw/cases/detail/d/',mapping_id) when theme_type='column' then CONCAT('https://hhh.com.tw/columns/detail/',mapping_id) when theme_type='product' then CONCAT('https://hhh.com.tw/product-post.php?id=',mapping_id) when theme_type='video' then CONCAT('https://hhh.com.tw/video-post.php?id=',mapping_id) when theme_type='brand' then CONCAT('https://hhh.com.tw/brand-index.php?brand_id=',mapping_id) ELSE '' END) url
  382. # # -- SELECT *
  383. # # FROM homepage_set
  384. # # left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  385. # # LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  386. # # LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  387. # # LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  388. # # LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  389. # # WHERE homepage_set.onoff='Y'
  390. # # AND outer_set = (SELECT oss_id from outer_site_set WHERE title='粉絲推薦')
  391. # # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  392. # # ORDER BY outer_set, inner_sort
  393. # # LIMIT """ + str(maxrow))
  394. # # x["data"] = []
  395. # # for c in records:
  396. # # if c['iframe'] is None:
  397. # # if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  398. # # c['J'] = c['J'].decode('utf8')
  399. # # if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  400. # # c['caption'] = c['caption'].decode('utf8')
  401. # # if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  402. # # c['short_desc'] = c['short_desc'].decode('utf8')
  403. # # a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  404. # # 'description': c['short_desc'], 'video': 'false'}
  405. # # else:
  406. # # tid = extract.video_id(str(c['iframe']))
  407. # # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  408. # # ccaption = ""
  409. # # cdescription = ""
  410. # # if isinstance(c['caption'], bytearray):
  411. # # ccaption = str(c['caption'].decode('utf8'))
  412. # # else:
  413. # # ccaption = str(c['caption'])
  414. # # if c['short_desc'] is not None:
  415. # # if isinstance(c['short_desc'], bytes):
  416. # # cdescription = str(c['short_desc'].decode('utf8'))
  417. # # else:
  418. # # cdescription = str(c['short_desc'])
  419. # # a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  420. # # 'description': cdescription, 'video': tid}
  421. # # x["data"].append(a)
  422. # # # 推薦設計師
  423. # # if x['id'] == 5:
  424. # # records = ExecuteQuery("""SELECT hdesigner_id,title,img_path,name FROM _hdesigner where onoff=1 order by dorder limit 12;
  425. # # """)
  426. # # x["data"] = []
  427. # # for c in records:
  428. # # a = {'imgUrl': c['img_path'],'name': c['title'] ,'designers_name':c['name'],'link': "/HHH_NEW/designers/index_designerList.php?cid=" + str(c['hdesigner_id'])}
  429. # # x["data"].append(a)
  430. # # 推薦設計師
  431. # if x['id'] == 5:
  432. # records_for_custom = ExecuteQuery(""" SELECT hd.hdesigner_id,hd.title,hd.img_path,hd.name
  433. # FROM homepage_set
  434. # LEFT JOIN _hdesigner hd ON mapping_id = hd.hdesigner_id
  435. # WHERE outer_set=9 AND hd.onoff='1'
  436. # AND homepage_set.onoff='Y'
  437. # AND(NOW() BETWEEN homepage_set.start_time AND homepage_set.end_time OR(homepage_set.start_time='0000-00-00 00:00:00' and homepage_set.end_time='0000-00-00 00:00:00') or (homepage_set.start_time is null and homepage_set.end_time is NULL))
  438. # ORDER BY inner_sort limit 12""")
  439. # #加入不重複id
  440. # id_use = []
  441. # for g in records_for_custom:
  442. # id_use.append(g['hdesigner_id'])
  443. # id_len = 12 - len(id_use)
  444. # print(id_use)
  445. # str_id_use=''
  446. # for k in id_use:
  447. # str_id_use+=' and hdesigner_id!=%s '%k
  448. # records = ExecuteQuery("""SELECT hdesigner_id,title,img_path,name FROM _hdesigner where onoff=1 """+str_id_use +""" order by dorder limit """+ str(id_len) +""" """)
  449. # x["data"] = []
  450. # for d in records_for_custom:
  451. # q = {'imgUrl': d['img_path'],'name': d['title'] ,'designers_name':d['name'],'link': "/HHH_NEW/designers/index_designerList.php?cid=" + str(d['hdesigner_id'])}
  452. # x["data"].append(q)
  453. # for c in records:
  454. # a = {'imgUrl': c['img_path'],'name': c['title'] ,'designers_name':c['name'],'link': "/HHH_NEW/designers/index_designerList.php?cid=" + str(c['hdesigner_id'])}
  455. # x["data"].append(a)
  456. # #=======================================================================================================================
  457. # # 加好物API
  458. # if x['id'] == 7:
  459. # records = ExecuteQuery(""" SELECT alt_use,adlogo,adhref FROM _had
  460. # WHERE adtype LIKE '合宜'
  461. # AND onoff='1'
  462. # """) #AND(NOW() BETWEEN start_time AND end_time OR(start_time='0000-00-00 00:00:00' and end_time='0000-00-00 00:00:00') or (start_time is null and end_time is NULL))
  463. # #ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)
  464. # # url = 'https://open.shopline.io/v1/products/search'
  465. # # params = {'per_page': 200, 'page': 1,"category_id":"6108deabe15ff9003e5cef08"}
  466. # # headers = {
  467. # # 'accept': 'application/json',
  468. # # 'authorization': 'Bearer '+access_token,
  469. # # 'User-Agent': 'Shopline test'
  470. # # }
  471. # # response = requests.get(url, params=params, headers=headers)
  472. # # use=response.json()
  473. # x["data"] = []
  474. # for d in records:
  475. # q = {'imgUrl': d['adlogo'],'title': d['alt_use'],'link': d['adhref']}
  476. # x["data"].append(q)
  477. # # for i in range(len(use['items'])):
  478. # # for i in range(len(use['items'])):
  479. # # if use['items'][i]['status']=='active':
  480. # # title = use['items'][i]['title_translations']['zh-hant']
  481. # # link = use['items'][i]['link']
  482. # # img = use['items'][i]['medias'][0]['images']['original']['url']
  483. # # a = {'imgUrl': img,'title': title ,'link':'https://shop.hhh.com.tw/products'+link}
  484. # # x["data"].append(a)
  485. # #=======================================================================================================================
  486. # # print(x["data"])
  487. # # if x['id'] == 9:
  488. # # records = ExecuteQuery(
  489. # # "SELECT id, (case when youtube_title = '' OR youtube_title IS NULL then (SELECT title FROM _hvideo where display_datetime < NOW() ORDER BY hvideo_id DESC LIMIT 1 ) ELSE youtube_title END) T, (case when youtube_id = '' OR youtube_id IS NULL then (SELECT iframe FROM _hvideo where display_datetime < NOW() ORDER BY hvideo_id DESC LIMIT 1) ELSE youtube_id end) Y FROM site_setup")
  490. # # for c in records:
  491. # # x['title'] = ""
  492. # # if isinstance(c['T'], bytearray):
  493. # # x['title'] = str(c['T'].decode('utf8'))
  494. # # else:
  495. # # x['title'] = str(c['T'])
  496. # # x['yt'] = extract.video_id(str(c['Y']))
  497. # # print(id)
  498. # # if x['id'] == 10:
  499. # # records = ExecuteQuery(
  500. # # "SELECT all_search_tag ast FROM site_setup")
  501. # # x["data"] = []
  502. # # for c in records:
  503. # # x["data"] = c['ast'].split(',')
  504. # # print(id)
  505. # # print(jData)
  506. # """ if not os.path.exists(hhhMBPath):
  507. # os.mkdir(hhhMBPath)
  508. # with open(hhhMBPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  509. # json.dump(jData, f, ensure_ascii=False, indent=4)
  510. # if not os.path.exists(hhhPCPath):
  511. # os.mkdir(hhhPCPath)
  512. # with open(hhhPCPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  513. # json.dump(jData, f, ensure_ascii=False, indent=4) """
  514. # with open('../json/' + filename, 'w', encoding='utf-8') as f:
  515. # json.dump(jData, f, ensure_ascii=False, indent=4)
  516. # return jData
  517. # genjson_new("data_index.json")
  518. while True:
  519. try:
  520. a=requests.get('https://m3.hhh.com.tw:18689/genjson_new')
  521. break
  522. except:
  523. print('bad:',j)
  524. time.sleep(5)
  525. d=a.json()
  526. print(d)
  527. with open('../json/data_index.json','w+',encoding="utf-8") as f:
  528. json.dump(d, f)
  529. cmd="""curl -X POST "https://api.cloudflare.com/client/v4/zones/8cb58022ad5743cfd9f088d5e3a261eb/purge_cache" -H "X-Auth-Email: web.dept.hhh@gmail.com" -H "X-Auth-Key:63e51d9a1638d66afcbfc3320aabec52304de" -H "Content-Type: application/json" --data '{"files":["https://hhh.com.tw/hhh-test/json/data_index.json"]}'"""
  530. os.system(cmd)