genjson_index.py 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. import os
  2. from typing import Optional
  3. import mysql.connector
  4. from dataset.util import ResultIter
  5. from fastapi import FastAPI
  6. from fastapi.middleware.cors import CORSMiddleware
  7. from pytrends.request import TrendReq
  8. from datetime import tzinfo
  9. import datetime
  10. from io import BytesIO
  11. from fastapi.responses import StreamingResponse
  12. import xlsxwriter
  13. import pandas as pd
  14. import dataset
  15. import html
  16. import json
  17. from pytube import extract
  18. import re
  19. import requests
  20. import json
  21. import requests
  22. from access_token import *
  23. app = FastAPI()
  24. origins = [
  25. "*"
  26. ]
  27. app.add_middleware(
  28. CORSMiddleware,
  29. allow_origins=origins,
  30. allow_credentials=True,
  31. allow_methods=["*"],
  32. allow_headers=["*"],
  33. )
  34. hhhMBPath = '../hhh-home-mb'
  35. hhhPCPath = '../hhh-home-pc'
  36. # connstr = 'mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4'
  37. #2022/12/13 change
  38. connstr = 'mysql://hhh7796hhh:lYmWsu^ujcA1@ec2-3-35-26-49.ap-northeast-2.compute.amazonaws.com:3306/xoops?charset=utf8mb4'
  39. def ExecuteQuery(isql):
  40. #2022/12/13 change
  41. #host='hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com',
  42. with mysql.connector.connect(
  43. host='ec2-3-35-26-49.ap-northeast-2.compute.amazonaws.com',
  44. database='xoops',
  45. user='hhh7796hhh',
  46. password='lYmWsu^ujcA1',
  47. use_unicode=True,
  48. charset='utf8',
  49. #collation='utf8_unicode_ci'
  50. ) as connection :
  51. with connection.cursor(dictionary=True) as cursor:
  52. # connection.set_charset_collation('utf8','utf8_general_ci')
  53. #cursor = connection.cursor(dictionary=True)
  54. cursor.execute(isql)
  55. return cursor.fetchall()
  56. def ExecuteCmd(isql):
  57. #2022/12/13 change
  58. #host='hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com',
  59. with mysql.connector.connect(
  60. host='ec2-3-35-26-49.ap-northeast-2.compute.amazonaws.com',
  61. database='xoops',
  62. user='hhh7796hhh',
  63. password='lYmWsu^ujcA1',
  64. use_unicode=True,
  65. charset='utf8',
  66. collation='utf8_unicode_ci'
  67. ) as connection:
  68. cursor = connection.cursor(dictionary=True)
  69. cursor.execute(isql)
  70. print(cursor.rowcount)
  71. connection.commit()
  72. return None
  73. @app.get("/ExportExecuteDetail")
  74. async def ExportExecuteDetail():
  75. with dataset.connect(connstr) as db:
  76. output = BytesIO()
  77. records = db.query(""" select f.exf_id, num 合約, company 合約公司,lv1 大項目,lv2 執行項, contract_time 合約到期日,price 金額,sales_man 業務,quota 額度,creator 建立者,is_close 狀態,sdate 上架日期,edate 下架日期,f.note 備註,designer 設計師,mobile 手機,telete 電話,contract_person 聯絡人,detail_status 合約名稱,d.create_time 建立時間,d.update_time 更新時間,last_update 最後更新 from execute_form f
  78. left join execute_detail d on f.exf_id=d.exf_id
  79. where f.is_delete='N' order BY f.exf_id DESC, exd_id
  80. """)
  81. df = pd.DataFrame(list(records))
  82. writer = pd.ExcelWriter(output)
  83. df.to_excel(writer, sheet_name='bar')
  84. writer.save()
  85. """ workbook = xlsxwriter.Workbook(output)
  86. worksheet = workbook.add_worksheet()
  87. for cols in records:
  88. worksheet.write(0, 0, 'ISBN')
  89. worksheet.write(0, 1, 'Name')
  90. worksheet.write(0, 2, 'Takedown date')
  91. worksheet.write(0, 3, 'Last updated')
  92. workbook.close() """
  93. output.seek(0)
  94. headers = {
  95. 'Content-Disposition': 'attachment; filename="execute_detail_all.xlsx"'
  96. }
  97. return StreamingResponse(output, headers=headers, media_type='application/octet-stream')
  98. @app.get("/")
  99. def read_root():
  100. return {"Hello": "World"}
  101. @app.get("/movexoopstostage")
  102. def movexoopstostage(designerid: str = "0", caseid: str = "0"):
  103. with dataset.connect(connstr) as db:
  104. db.query(
  105. "replace INTO stage._hdesigner SELECT * FROM xoops._hdesigner WHERE hdesigner_id IN ('" + designerid.replace(',', "','")+"');")
  106. db.query(
  107. "replace INTO stage._hcase SELECT * FROM xoops._hcase WHERE hcase_id IN ('"+caseid.replace(',', "','")+"');")
  108. db.query(
  109. "replace INTO stage._hcase_img SELECT * FROM xoops._hcase_img WHERE hcase_id IN ('"+caseid.replace(',', "','")+"');")
  110. return {"success"}
  111. @app.get("/movepxoopstostage")
  112. def movepxoopstostage(brandid: str = "0", productid: str = "0"):
  113. with dataset.connect(connstr) as db:
  114. db.query(
  115. "replace INTO stage._hbrand SELECT * FROM xoops._hbrand WHERE hbrand_id IN ('" + brandid.replace(',', "','")+"');")
  116. db.query(
  117. "replace INTO stage._hbrand_page SELECT * FROM xoops._hbrand_page WHERE hbrand_id IN ('" + brandid.replace(',', "','")+"');")
  118. db.query(
  119. "replace INTO stage._hproduct SELECT * FROM xoops._hproduct WHERE id IN ('"+productid.replace(',', "','")+"');")
  120. db.query(
  121. "replace INTO stage._hproduct_img SELECT * FROM xoops._hproduct_img WHERE hproduct_id IN ('"+productid.replace(',', "','")+"');")
  122. return {"success"}
  123. @app.get("/movecxoopstostage")
  124. def movecxoopstostage(columnid: str = "0"):
  125. with dataset.connect(connstr) as db:
  126. db.query(
  127. "replace INTO stage._hcolumn SELECT * FROM xoops._hcolumn WHERE hcolumn_id IN ('" + columnid.replace(',', "','")+"');")
  128. db.query(
  129. "replace INTO stage._hcolumn_img SELECT * FROM xoops._hcolumn_img WHERE hcolumn_id IN ('" + columnid.replace(',', "','")+"');")
  130. db.query(
  131. "replace INTO stage._hcolumn_page SELECT * FROM xoops._hcolumn_page WHERE hcolumn_id IN ('" + columnid.replace(',', "','")+"');")
  132. return {"success"}
  133. @app.get("/genjson")
  134. def genjson(filename: str = "realtime.json"):
  135. jData = json.load(open(hhhMBPath+'/json/data.json', encoding='utf8'))
  136. 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 '首八大%' ")
  137. for x in jData:
  138. # 頂部輪播區-新刊頭
  139. if x['id'] == 0:
  140. records = ExecuteQuery("""SELECT adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  141. WHERE adtype LIKE '新刊頭%'
  142. AND onoff='1'
  143. 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))
  144. ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  145. x["data"] = []
  146. for c in records:
  147. a = {'imgUrl': c['mlo'], 'link': str(
  148. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp'])}
  149. x["data"].append(a)
  150. # print(x["data"])
  151. # 主要輪播區-首八大
  152. if x['id'] == 1:
  153. records = ExecuteQuery("""SELECT adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  154. WHERE adtype LIKE '首八大%'
  155. AND onoff='1'
  156. 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))
  157. ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  158. x["data"] = []
  159. for c in records:
  160. a = {'imgUrl': c['mlo'], 'link': str(
  161. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp'])}
  162. x["data"].append(a)
  163. # print(x["data"])
  164. #tab區塊-最夯設計, 影音實錄, 專欄文章
  165. if x['id'] == 2:
  166. x["data"] = []
  167. records = ExecuteQuery("""SELECT caption TT ,cover IMG, CONCAT('https://hhh.com.tw/cases/detail/',hcase_id,'/') LK, short_desc txt
  168. from _hcase
  169. left join _hdesigner ON _hcase.hdesigner_id=_hdesigner.hdesigner_id
  170. WHERE
  171. _hcase.onoff='1' AND _hdesigner.onoff='1'
  172. AND(NOW() > sdate)
  173. ORDER BY hcase_id DESC
  174. LIMIT 3""")
  175. a = {'tab': '最夯設計', 'data': []}
  176. for c in records:
  177. ad = {'imgUrl': c['IMG'], 'link': c['LK'],
  178. 'title': c['TT'], 'description': c['txt']}
  179. a['data'].append(ad)
  180. x["data"].append(a)
  181. records = ExecuteQuery("""SELECT title TT,iframe IMG , CONCAT('https://hhh.com.tw/video-post.php?id=',hvideo_id) LK , name
  182. from _hvideo where display_datetime < NOW()
  183. ORDER BY hvideo_id DESC
  184. LIMIT 4""")
  185. a = {'tab': '影音實錄', 'data': []}
  186. cnt = 0
  187. for c in records:
  188. if cnt == 0:
  189. cnt += 1
  190. continue
  191. tid = extract.video_id(c['IMG'])
  192. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  193. ad = {'imgUrl': timg, 'link': c['LK'],
  194. 'title': c['name'], 'description': c['TT']}
  195. a['data'].append(ad)
  196. x["data"].append(a)
  197. records = ExecuteQuery("""SELECT ctitle TT,clogo IMG, CONCAT('https://hhh.com.tw/columns/detail/',hcolumn_id,'/') LK, cdesc
  198. from _hcolumn
  199. WHERE onoff='1'
  200. AND NOW() > sdate
  201. ORDER BY hcolumn_id DESC
  202. LIMIT 3""")
  203. a = {'tab': '專欄文章', 'data': []}
  204. for c in records:
  205. ad = {'imgUrl': c['IMG'], 'link': c['LK'],
  206. 'title': c['TT'], 'description': c['cdesc']}
  207. a['data'].append(ad)
  208. x["data"].append(a)
  209. # print(x["data"])
  210. # 主題企劃區
  211. if x['id'] == 3:
  212. records = ExecuteQuery("""SELECT logo lo, CONCAT('https://hhh.com.tw/topic/detail/',htopic_id,'/') lk, `desc`, title FROM _htopic
  213. WHERE onoff = '1'
  214. ORDER BY htopic_id DESC limit 3""")
  215. x["data"] = []
  216. for c in records:
  217. a = {'imgUrl': c['lo'], 'link': str(
  218. c['lk']), 'video': 'false', 'description': c['desc'], 'title': c['title']}
  219. x["data"].append(a)
  220. # print(x["data"])
  221. # 編輯精選
  222. if x['id'] == 4:
  223. records = ExecuteQuery("""SELECT hcolumn_id, ctitle, clogo,cdesc
  224. FROM homepage_set
  225. LEFT JOIN _hcolumn ON mapping_id = hcolumn_id
  226. WHERE outer_set=8
  227. AND homepage_set.onoff='Y'
  228. 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))
  229. ORDER BY inner_sort""")
  230. x["data"] = []
  231. for c in records:
  232. a = {'imgUrl': c['clogo'], 'link': "https://hhh.com.tw/columns/detail/" + str(
  233. c['hcolumn_id']) + "/", 'title': c['ctitle'], 'video': 'false', 'description': c['cdesc']}
  234. x["data"].append(a)
  235. # print(x["data"])
  236. # 首列表廣告
  237. if x['id'] == 5:
  238. records = ExecuteQuery("""SELECT adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  239. WHERE adtype LIKE '首列表廣告%'
  240. AND onoff='1'
  241. 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))
  242. ORDER BY adtype""")
  243. x["data"] = []
  244. for c in records:
  245. a = {'imgUrl': c['mlo'], 'link': str(
  246. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp'])}
  247. x["data"].append(a)
  248. # print(x["data"])
  249. # 來選好物區
  250. if x['id'] == 6:
  251. records = ExecuteQuery(
  252. "SELECT max_row from outer_site_set WHERE title='來選好貨'")
  253. maxrow = 1
  254. for c in records:
  255. maxrow = c['max_row']
  256. 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
  257. , (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
  258. -- SELECT *
  259. FROM homepage_set
  260. left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  261. LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  262. LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  263. LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  264. WHERE homepage_set.onoff='Y'
  265. AND outer_set = (SELECT oss_id from outer_site_set WHERE title='來選好貨')
  266. 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))
  267. ORDER BY outer_set, inner_sort)
  268. UNION
  269. (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) + """)
  270. LIMIT """ + str(maxrow))
  271. x["data"] = []
  272. for c in records:
  273. #print(c)
  274. if c['iframe'] is None:
  275. if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  276. c['J'] = c['J'].decode('utf8')
  277. if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  278. c['caption'] = c['caption'].decode('utf8')
  279. if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  280. c['short_desc'] = c['short_desc'].decode('utf8')
  281. a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  282. 'description': c['short_desc'], 'video': 'false'}
  283. else:
  284. tid = extract.video_id(str(c['iframe']))
  285. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  286. ccaption = ""
  287. cdescription = ""
  288. if isinstance(c['caption'], bytearray):
  289. ccaption = str(c['caption'].decode('utf8'))
  290. else:
  291. ccaption = str(c['caption'])
  292. if c['short_desc'] is not None:
  293. if isinstance(c['short_desc'], bytes):
  294. cdescription = str(c['short_desc'].decode('utf8'))
  295. else:
  296. cdescription = str(c['short_desc'])
  297. a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  298. 'description': cdescription, 'video': tid}
  299. x["data"].append(a)
  300. # print(x["data"])
  301. # 本週推薦
  302. if x['id'] == 7:
  303. records = ExecuteQuery(
  304. "SELECT max_row from outer_site_set WHERE title='本週推薦'")
  305. maxrow = 1
  306. for c in records:
  307. maxrow = c['max_row']
  308. records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  309. 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
  310. , (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
  311. -- SELECT *
  312. FROM homepage_set
  313. left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  314. LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  315. LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  316. LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  317. LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  318. WHERE homepage_set.onoff='Y'
  319. AND outer_set = (SELECT oss_id from outer_site_set WHERE title='本週推薦')
  320. 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))
  321. ORDER BY outer_set, inner_sort
  322. LIMIT """ + str(maxrow))
  323. x["data"] = []
  324. for c in records:
  325. if c['iframe'] is None:
  326. if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  327. c['J'] = c['J'].decode('utf8')
  328. if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  329. c['caption'] = c['caption'].decode('utf8')
  330. if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  331. c['short_desc'] = c['short_desc'].decode('utf8')
  332. a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  333. 'description': c['short_desc'], 'video': 'false'}
  334. else:
  335. tid = extract.video_id(str(c['iframe']))
  336. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  337. ccaption = ""
  338. cdescription = ""
  339. if isinstance(c['caption'], bytearray):
  340. ccaption = str(c['caption'].decode('utf8'))
  341. else:
  342. ccaption = str(c['caption'])
  343. if c['short_desc'] is not None:
  344. if isinstance(c['short_desc'], bytes):
  345. cdescription = str(c['short_desc'].decode('utf8'))
  346. else:
  347. cdescription = str(c['short_desc'])
  348. a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  349. 'description': cdescription, 'video': tid}
  350. x["data"].append(a)
  351. # print(x["data"])
  352. # 粉絲推薦
  353. if x['id'] == 8:
  354. records = ExecuteQuery(
  355. "SELECT max_row from outer_site_set WHERE title='粉絲推薦'")
  356. maxrow = 1
  357. for c in records:
  358. maxrow = c['max_row']
  359. records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  360. 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
  361. , (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
  362. -- SELECT *
  363. FROM homepage_set
  364. left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  365. LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  366. LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  367. LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  368. LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  369. WHERE homepage_set.onoff='Y'
  370. AND outer_set = (SELECT oss_id from outer_site_set WHERE title='粉絲推薦')
  371. 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))
  372. ORDER BY outer_set, inner_sort
  373. LIMIT """ + str(maxrow))
  374. x["data"] = []
  375. for c in records:
  376. if c['iframe'] is None:
  377. if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  378. c['J'] = c['J'].decode('utf8')
  379. if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  380. c['caption'] = c['caption'].decode('utf8')
  381. if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  382. c['short_desc'] = c['short_desc'].decode('utf8')
  383. a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  384. 'description': c['short_desc'], 'video': 'false'}
  385. else:
  386. tid = extract.video_id(str(c['iframe']))
  387. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  388. ccaption = ""
  389. cdescription = ""
  390. if isinstance(c['caption'], bytearray):
  391. ccaption = str(c['caption'].decode('utf8'))
  392. else:
  393. ccaption = str(c['caption'])
  394. if c['short_desc'] is not None:
  395. if isinstance(c['short_desc'], bytes):
  396. cdescription = str(c['short_desc'].decode('utf8'))
  397. else:
  398. cdescription = str(c['short_desc'])
  399. a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  400. 'description': cdescription, 'video': tid}
  401. x["data"].append(a)
  402. # print(x["data"])
  403. if x['id'] == 9:
  404. records = ExecuteQuery(
  405. "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")
  406. for c in records:
  407. x['title'] = ""
  408. if isinstance(c['T'], bytearray):
  409. x['title'] = str(c['T'].decode('utf8'))
  410. else:
  411. x['title'] = str(c['T'])
  412. x['yt'] = extract.video_id(str(c['Y']))
  413. # print(id)
  414. if x['id'] == 10:
  415. records = ExecuteQuery(
  416. "SELECT all_search_tag ast FROM site_setup")
  417. x["data"] = []
  418. for c in records:
  419. x["data"] = c['ast'].split(',')
  420. # print(id)
  421. # print(jData)
  422. """ if not os.path.exists(hhhMBPath):
  423. os.mkdir(hhhMBPath)
  424. with open(hhhMBPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  425. json.dump(jData, f, ensure_ascii=False, indent=4)
  426. if not os.path.exists(hhhPCPath):
  427. os.mkdir(hhhPCPath)
  428. with open(hhhPCPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  429. json.dump(jData, f, ensure_ascii=False, indent=4) """
  430. return jData
  431. @app.get("/gencase")
  432. def gencase(id: str = "14151", sort: str = "new", page: str="1"):
  433. with dataset.connect(connstr) as db:
  434. jData = json.load(open(hhhMBPath+'/json/cases.json', encoding='utf8'))
  435. records = db.query("""SELECT *, c.style cstyle, c.style2 cstyle2 FROM _hcase c
  436. LEFT JOIN _hdesigner d ON c.hdesigner_id = d.hdesigner_id
  437. WHERE c.hcase_id = '""" + id + """' AND c.onoff='1' AND d.onoff='1' and c.sdate < now() """)
  438. # print(jData)
  439. for x in jData:
  440. tmpCaseDetail = []
  441. icount = 0
  442. for c in records:
  443. icount += 1
  444. #tmpCaseDetail.append({"CaseDetailImg": c["cimg"]})
  445. #x["CaseDetail"] = tmpCaseDetail
  446. if c != None:
  447. x["designerid"] = str(c["hdesigner_id"])
  448. x["CaseId"] = str(c["hcase_id"])
  449. x["Casetitle"] = c["caption"]
  450. x["CaseTeamName"] = c["name"]
  451. x["CaseCompany"] = c["title"]
  452. x["CaseCompanyAddress"] = c["address"]
  453. x["CaseCompanyTel"] = c["phone"]
  454. x["CaseCompanyEmail"] = c["mail"]
  455. x["CaseCompanyWeb"] = c["website"]
  456. x["CaseDate"] = str(c["sdate"])
  457. x["CaseViews"] = c["viewed"]
  458. x["CaseCoverImg"] = c["cover"]
  459. x["CaseImgAmount"] = icount
  460. x["CaseStyle"] = c["cstyle"]
  461. x["CaseHouse"] = c["layout"]
  462. x["CaseSize"] = c["area"]
  463. x["CaseProject"] = ""
  464. x["CaseDataMember"] = c["member"]
  465. x["CaseDataSize"] = c["area"]
  466. x["CaseDataStyle"] = c["cstyle"] + c["cstyle2"]
  467. x["CaseDataType"] = c["type"]
  468. x["CaseDataSituation"] = c["condition"]
  469. x["CaseDataImgProvide"] = c["provider"]
  470. x["CaseDataSpace"] = c["layout"]
  471. x["CaseDataMaterial"] = c["materials"]
  472. x["ContactFreeTel"] = c["service_phone"]
  473. x["ContactDesignerImg"] = c["img_path"]
  474. x["CasePageLink"] = ""
  475. x["CasePageprev"] = ""
  476. #x["CaseTag"]= []
  477. #相同設計師的個案
  478. sql = """SELECT * FROM _hcase c
  479. WHERE hdesigner_id = '""" + x["designerid"] + """' and hcase_id <> '""" + x["CaseId"] + """' and sdate < now() AND c.onoff='1'
  480. ORDER BY """ + ("sdate" if sort == 'new' else 'viewed') + """ DESC
  481. LIMIT """ + str((int(page) - 1)*12) + """,12
  482. """
  483. cases = db.query(sql)
  484. tmpOtherCases = []
  485. for other in cases:
  486. tmpOtherCase = {}
  487. tmpOtherCase["designerid"] = str(other["hdesigner_id"])
  488. tmpOtherCase["casesid"] = str(other["hcase_id"])
  489. tmpOtherCase["Views"] = other["viewed"]
  490. tmpOtherCase["ProfileImg"] = other["cover"]
  491. tmpTags = []
  492. for tag in other["tag"].split(','):
  493. tmpTags.append({"Tag": tag , "TagLink": "" })
  494. tmpOtherCase["ProfileTag"] = tmpTags
  495. tmpOtherCases.append(tmpOtherCase)
  496. x["DesignerProfile"] = tmpOtherCases
  497. #相同風格的個案
  498. sql = """SELECT * FROM _hcase c
  499. WHERE style = '""" + x["CaseStyle"] + """' and hcase_id <> '""" + x["CaseId"] + """' and sdate < now() AND c.onoff='1'
  500. ORDER BY """ + ("sdate" if sort == 'new' else 'viewed') + """ DESC
  501. LIMIT """ + str((int(page) - 1)*12) + """,12
  502. """
  503. cases = db.query(sql)
  504. tmpOtherCases = []
  505. for other in cases:
  506. tmpOtherCase = {}
  507. tmpOtherCase["designerid"] = str(other["hdesigner_id"])
  508. tmpOtherCase["casesid"] = str(other["hcase_id"])
  509. tmpOtherCase["Views"] = other["viewed"]
  510. tmpOtherCase["ProfileImg"] = other["cover"]
  511. tmpTags = []
  512. for tag in other["tag"].split(','):
  513. tmpTags.append({"Tag": tag , "TagLink": "" })
  514. tmpOtherCase["ProfileTag"] = tmpTags
  515. tmpOtherCases.append(tmpOtherCase)
  516. x["StyleProfile"] = tmpOtherCases
  517. #相同風格的RANDOM 10筆
  518. #cases = db.query("""SELECT * FROM _hcase c
  519. #WHERE style = '""" + x["CaseStyle"] + """' and hcase_id <> '""" + x["CaseId"] + """' and sdate < now() AND c.onoff='1'
  520. #ORDER BY RAND()
  521. #LIMIT 10
  522. #""")
  523. """ tmpOtherCases = []
  524. for other in cases:
  525. tmpOtherCase = {}
  526. tmpOtherCase["designerid"] = str(other["hdesigner_id"])
  527. tmpOtherCase["casesid"] = str(other["hcase_id"])
  528. tmpOtherCase["PortfoliolImg"] = other["cover"]
  529. tmpOtherCase["PortfoliolLink"] = ""
  530. tmpOtherCase["PortfoliolImgAlt"] = other["caption"]
  531. tmpOtherCases.append(tmpOtherCase)
  532. x["OtherStylePortfolio"]= tmpOtherCases """
  533. # print(x)
  534. # print(jData)
  535. """ if not os.path.exists(hhhMBPath):
  536. os.mkdir(hhhMBPath)
  537. with open(hhhMBPath+'/json/cases-' + id + '.json', 'w', encoding='utf-8') as f:
  538. json.dump(jData, f, ensure_ascii=False, indent=4) """
  539. return jData
  540. @app.get("/gendesigner")
  541. async def gendesigner(id: str = "447", sort: str = "new", page: str = "1"):
  542. with dataset.connect(connstr) as db:
  543. jData = json.load(open(hhhMBPath+'/json/designers.json', encoding='utf8'))
  544. records = db.query("""SELECT * FROM _hdesigner d
  545. WHERE d.hdesigner_id = '""" + id + """' AND d.onoff='1' """)
  546. check_len=[]
  547. for c in records:
  548. check_len.append(c)
  549. if len(check_len)==0:
  550. return []
  551. # print(jData)
  552. for x in jData:
  553. tmpCaseDetail = []
  554. icount = 0
  555. for c in records:
  556. icount += 1
  557. # tmpCaseDetail.append({"CaseDetailImg":c["cimg"]})
  558. if page == "1":
  559. x["id"] = c["hdesigner_id"]
  560. x["BannerImg"] = c["background"]
  561. x["BannerImg_mobile"] = c['background_mobile']
  562. x["CompanyName"] = c["title"].replace("\n","<br>")
  563. x["DesignerName"] = c["name"]
  564. x["Designerimg"] = c["img_path"]
  565. x["Description"] = c["seo"]
  566. x["Approve"] = c["position"]
  567. x["FB_link"] = c["fbpageurl"]
  568. # x["order_computer"] = c["order_computer"]
  569. # x["order_mb"] = c["order_mb"]
  570. if c["service_phone"]!='':
  571. if ',' not in c["service_phone"]:
  572. service_phone = c["service_phone"]
  573. else:
  574. part1=c["service_phone"][0:4]
  575. part2=c["service_phone"][4:7]
  576. part3=c["service_phone"][7:10]
  577. part4=c["service_phone"].split(',')[1]
  578. service_phone = part1+'-'+part2+'-'+part3+'#'+part4
  579. else:
  580. service_phone=''
  581. phone_list=[]
  582. for k1 in c["phone"].split(','):
  583. phone_list.append({"title": "諮詢專線:", "link":'tel:'+k1, "data":k1})
  584. x["Basics"] = []
  585. if service_phone!='':
  586. x["Basics"].append({"title": "免費專線:","link": 'tel:'+c["service_phone"], "data": service_phone})
  587. if c["phone"]!='':
  588. for k2 in phone_list:
  589. x["Basics"].append(k2)
  590. if len(c["fax"])!=0:
  591. x["Basics"].append({"title": "公司傳真:", "link": "fax:"+c["fax"], "data": c["fax"]})
  592. if len(c["address"])!=0:
  593. x["Basics"].append({"title": "公司地址:", "link": "https://www.google.com/search?q="+c["address"], "data": c["address"]})
  594. if len(c["mail"])!=0:
  595. x["Basics"].append({"title": "電子信箱:", "link": "mailto:"+c["mail"], "data": c["mail"]})
  596. if len(c["website"])!=0:
  597. x["Basics"].append({"title": "公司網址:", "link": c["website"], "data": c["website"]})
  598. blog_list=re.findall(r'href="(.*?)"',c["blog"])
  599. if len(blog_list)==0:
  600. blog_list=re.findall(r'http.*',c["blog"])
  601. if len(blog_list)!=0:
  602. for k3 in blog_list:
  603. x["Basics"].append({"title": "其他連結:", "link": k3, "data": k3})
  604. # x["Basics"] = [
  605. # {"title": "免費專線:","link": 'tel:'+c["service_phone"], "data": service_phone},
  606. # # {"title": "諮詢專線:", "link": c["phone"], "data": c["phone"]},
  607. # {"title": "諮詢專線:", "link": c["phone"], "data": c["phone"]},
  608. # {"title": "公司傳真:", "link": c["fax"], "data": c["fax"]},
  609. # {"title": "公司地址:", "link": c["address"], "data": c["address"]},
  610. # {"title": "電子信箱:", "link": c["mail"], "data": c["mail"]},
  611. # {"title": "公司網址:", "link": c["website"], "data": c["website"]}
  612. # ]
  613. x["FreeCall"] = c["service_phone"]
  614. x["ConsoleCall_1"] = c["phone"]
  615. x["ConsoleCall_2"] = c["phone"]
  616. x["Fax"] = c["fax"]
  617. x["Address"] = c["address"]
  618. x["Email"] = c["mail"]
  619. x["Web"] = c["website"]
  620. x["Branches"] = []
  621. branches = db.query("""SELECT * FROM designer_branch br
  622. WHERE br.designer_id = '""" + id + """' """)
  623. for branch in branches:
  624. tmpobj = {
  625. "title": branch["title"],
  626. "address": branch["address"],
  627. "address_link" : "https://www.google.com/search?q="+branch["address"],
  628. "tel": branch["tel"],
  629. "tel_link": "tel:"+branch["tel"],
  630. "fax": branch["fax"],
  631. "fax_link": "fax:"+branch["fax"]
  632. }
  633. x["Branches"].append(tmpobj)
  634. x["Budget"] = c["budget"]
  635. x["Square"] = c["area"]
  636. x["SpecialCase"] = c["special"]
  637. x["Charge"] = c["charge"]
  638. x["Pay"] = c["payment"]
  639. x["WorkLoc"] = c["region"]
  640. x["WorkType"] = c["type"]
  641. x["WorkStyle"] = c["style"]
  642. x["WorkBudget"] = c["budget"]
  643. x["Terms"] = []
  644. if c["budget"]!='':
  645. x["Terms"].append({"title": "接案預算:", "data": c["budget"]})
  646. if c["area"]!='':
  647. x["Terms"].append({"title": "接案坪數:", "data": c["area"]})
  648. if c["special"]!='':
  649. x["Terms"].append({"title": "特殊接案:", "data": c["special"]})
  650. if c["charge"]!='':
  651. x["Terms"].append({"title": "收費方式:", "data": c["charge"]})
  652. if c["payment"]!='':
  653. x["Terms"].append({"title": "付費方式:", "data": c["payment"]})
  654. if c["region"]!='':
  655. x["Terms"].append({"title": "接案區域:", "data": c["region"]})
  656. if c["type"]!='':
  657. x["Terms"].append({"title": "接案類型:", "data": c["type"]})
  658. if c["style"]!='':
  659. x["Terms"].append({"title": "接案風格:", "data": c["style"]})
  660. x["scMedia"] = [
  661. {"name": "Facebook", "img": "https://hhh.com.tw/assets/images/rv_web/fb.svg",
  662. "link": c["fbpageurl"]},
  663. {"name": "Line", "img": "https://hhh.com.tw/assets/images/rv_web/line.svg",
  664. "link": c["line_link"]},
  665. {"name": "Wechat", "img": "https://hhh.com.tw/assets/images/rv_web/wechat.svg",
  666. "link": c["fbpageurl"]},
  667. {"name": "email", "img": "https://hhh.com.tw/assets/images/rv_web/share.svg",
  668. "link": c["mail"]},
  669. {"name": "Like", "img": "https://hhh.com.tw/assets/images/rv_web/like-o.svg", "link": ""}
  670. ]
  671. x_info = []
  672. if len(c["idea"])!=0:
  673. x_info.append({"title": "設計理念", "data": c["idea"]})
  674. if len(c["taxid"])!=0:
  675. x_info.append( {"title": "公司統編", "data": c["taxid"]})
  676. if len(c["career"])!=0:
  677. x_info.append({"title": "相關經歷", "data": c["career"]})
  678. if len(c["license"])!=0:
  679. x_info.append( {"title": "專業證照", "data": c["license"].replace('\r\n','<br />')})
  680. if len(c["awards"])!=0:
  681. x_info.append( {"title": "獲獎紀錄", "data": c["awards"].replace('\r\n','<br />')})
  682. x["Content"] = [
  683. {
  684. "Title": "設計師作品",
  685. "mb_title": "作品",
  686. "Tabtag": "intro",
  687. "Display_mb": "true",
  688. "isActive": "true",
  689. "Carddata": [],
  690. "total_all":0
  691. },
  692. {
  693. "Title": "設計師影音",
  694. "mb_title": "影音",
  695. "Tabtag": "video",
  696. "Display_mb": "true",
  697. "isActive": "true",
  698. "Carddata": [],
  699. "total_all":0
  700. },
  701. {
  702. "Title": "設計師專欄",
  703. "mb_title": "專欄",
  704. "Tabtag": "columns",
  705. "Display_mb": "true",
  706. "isActive": "true",
  707. "Carddata": [],
  708. "total_all":0
  709. },
  710. {
  711. "Title": "VR360",
  712. "mb_title": "VR",
  713. "Tabtag": "vr360",
  714. "Display_mb": "false",
  715. "isActive": "true",
  716. "Carddata": [],
  717. "total_all":0
  718. },
  719. {
  720. "Title": "設計師公司簡介",
  721. "mb_title": "公司簡介",
  722. "Tabtag": "company",
  723. "Display_mb": "true",
  724. "isActive": "true",
  725. "Carddata": [],
  726. "info":x_info
  727. # "info": [
  728. # {"title": "設計理念", "data": c["idea"]},
  729. # {"title": "公司統編", "data": c["taxid"]},
  730. # {"title": "相關經歷", "data": c["career"]},
  731. # {"title": "專業證照", "data": c["license"]},
  732. # {"title": "獲獎紀錄", "data": c["awards"]}
  733. # ]
  734. }
  735. ]
  736. records = db.query("""SELECT count(1) FROM _hcase c WHERE c.hdesigner_id = '""" + id + """' AND c.onoff='1' and c.sdate < now(); """ )
  737. for c in records:
  738. x["Content"][0]["total_all"] = str(c["count(1)"])
  739. records = db.query("""SELECT count(1) FROM _hvideo v WHERE v.hdesigner_id = '""" + id + """' AND display_datetime < NOW() and iframe<>'' ;""")
  740. for c in records:
  741. x["Content"][1]["total_all"] = str(c["count(1)"])
  742. records = db.query("""SELECT count(1) FROM _hcolumn c WHERE onoff=1 AND (c.hdesigner_ids LIKE '""" + id + """,%' OR c.hdesigner_ids LIKE '%,""" + id + """,%' OR c.hdesigner_ids LIKE '%,""" + id + """' OR c.hdesigner_ids = '""" + id + """') ;""")
  743. for c in records:
  744. x["Content"][2]["total_all"] = str(c["count(1)"])
  745. records = db.query("""SELECT count(1) FROM _hcase c WHERE c.hdesigner_id = '""" + id + """' and istaging != '' AND c.onoff='1' and c.sdate < now();""")
  746. for c in records:
  747. x["Content"][3]["total_all"] = str(c["count(1)"])
  748. # 設計師作品
  749. x["Content"][0]["Carddata"] = []
  750. cases = db.query("""SELECT tag,cover,caption,hcase_id,viewed,sdate,style,style2,type,`condition` FROM _hcase c
  751. WHERE c.hdesigner_id = '""" + id + """' AND c.onoff='1' and c.sdate < now()
  752. ORDER BY """ + ("sdate" if sort == 'new' else 'corder ASC,viewed') + """ DESC
  753. LIMIT """ + str((int(page) - 1)*12) + """,12
  754. """)
  755. for case in cases:
  756. tag_use = ''
  757. if case['style']!='':
  758. tag_use += case['style'].strip()
  759. tag_use += ','
  760. if case['style2']!='':
  761. tag_use += case['style2'].strip()
  762. tag_use += ','
  763. if case['type']!='':
  764. tag_use += case['type'].strip()
  765. tag_use += ','
  766. if case['condition']!='':
  767. tag_use += case['condition'].strip()
  768. tmpobj = {
  769. "url": "https://hhh.com.tw/cases/detail/d/"+str(case["hcase_id"]),
  770. "imgURL": case["cover"].replace('/_hcase/', '/_hcase_orig/').replace('/_hcase_img/', '/_hcase_img_orig/'),
  771. "title": case["caption"],
  772. "tag": [{"name": tag, "link": "https://hhh.com.tw/search/lists/case/{}-keyword/".format(tag)} for tag in tag_use.split(',')],
  773. # "tag": [{"name": tag, "link": "https://hhh.com.tw/search/lists/case/{}-keyword/".format(tag)} for tag in case["tag"].split(',')],
  774. "views": case["viewed"],
  775. "dateSort": str(case["sdate"])
  776. }
  777. x["Content"][0]["Carddata"].append(tmpobj)
  778. # 設計師影音
  779. # https://i.ytimg.com/vi/y6VmaLC7O9Y/hqdefault.jpg
  780. x["Content"][1]["Carddata"] = []
  781. # videos = db.query("""SELECT tag_vpattern,iframe,title,hvideo_id,viewed,display_datetime FROM _hvideo v
  782. # WHERE v.hdesigner_id = '""" + id + """' AND display_datetime < NOW() and iframe<>''
  783. # ORDER BY """ + ("hvideo_id" if sort == 'new' else 'viewed') + """ DESC
  784. # LIMIT """ + str((int(page) - 1)*12) + """,12
  785. # """)
  786. videos = db.query("""SELECT tag_vpattern,iframe,title,hvideo_id,viewed,display_datetime FROM _hvideo v
  787. WHERE v.hdesigner_id = '""" + id + """' AND display_datetime < NOW() and iframe<>''
  788. ORDER BY """+ "hvideo_id" + """ DESC
  789. LIMIT """ + str((int(page) - 1)*12) + """,12
  790. """)
  791. for video in videos:
  792. print(str(video['iframe']))
  793. tmpobj = {
  794. "url": "https://hhh.com.tw/video-post.php?id="+str(video['hvideo_id']),
  795. "imgURL": "https://i.ytimg.com/vi/" + extract.video_id(html.unescape(str(video['iframe'])))+"/hqdefault.jpg",
  796. "title": video["title"],
  797. "tag": [{"name": tag, "link": "https://hhh.com.tw/search/lists/video/{}-keyword/".format(tag)} for tag in video["tag_vpattern"].split(',')],
  798. "views": video["viewed"],
  799. "dateSort": str(video["display_datetime"])
  800. }
  801. x["Content"][1]["Carddata"].append(tmpobj)
  802. # 設計師專欄
  803. # x["Content"][2]["Carddata"] = []
  804. # columns = db.query("""SELECT Ctag,clogo,ctitle,hcolumn_id,viewed,sdate FROM _hcolumn c
  805. # WHERE onoff=1 AND (hdesigner_ids LIKE '""" + id + """,%' OR hdesigner_ids LIKE '%,""" + id + """,%' OR hdesigner_ids LIKE '%,""" + id + """' OR hdesigner_ids = '""" + id + """')
  806. # ORDER BY """ + ("sdate" if sort == 'new' else 'viewed') + """ DESC
  807. # LIMIT """ + str((int(page) - 1)*12) + """,12
  808. # """)
  809. x["Content"][2]["Carddata"] = []
  810. columns = db.query("""SELECT Ctag,clogo,ctitle,hcolumn_id,viewed,sdate FROM _hcolumn c
  811. WHERE onoff=1 AND (hdesigner_ids LIKE '""" + id + """,%' OR hdesigner_ids LIKE '%,""" + id + """,%' OR hdesigner_ids LIKE '%,""" + id + """' OR hdesigner_ids = '""" + id + """')
  812. ORDER BY """ + "sdate" + """ DESC
  813. LIMIT """ + str((int(page) - 1)*12) + """,12
  814. """)
  815. for column in columns:
  816. tmpobj = {
  817. "url": "https://hhh.com.tw/columns/detail/"+str(column['hcolumn_id']),
  818. "imgURL": column['clogo'],
  819. "title": column["ctitle"],
  820. "tag": [] if not column["Ctag"] else [{"name": tag, "link": "https://hhh.com.tw/search/lists/column/{}-keyword/".format(tag)} for tag in column["Ctag"].split(',')],
  821. "views": column["viewed"],
  822. "dateSort": str(column["sdate"])
  823. }
  824. x["Content"][2]["Carddata"].append(tmpobj)
  825. # VR360
  826. # x["Content"][3]["Carddata"] = []
  827. # cases = db.query("""SELECT tag,cover,caption,hcase_id,viewed,sdate FROM _hcase c
  828. # WHERE c.hdesigner_id = '""" + id + """' and istaging != '' AND c.onoff='1'
  829. # ORDER BY """ + ("sdate" if sort == 'new' else 'viewed') + """ DESC
  830. # LIMIT """ + str((int(page) - 1)*12) + """,12
  831. # """)
  832. x["Content"][3]["Carddata"] = []
  833. cases = db.query("""SELECT tag,cover,caption,hcase_id,viewed,sdate FROM _hcase c
  834. WHERE c.hdesigner_id = '""" + id + """' and istaging != '' AND c.onoff='1' and c.sdate < now()
  835. ORDER BY """ + "sdate" + """ DESC
  836. LIMIT """ + str((int(page) - 1)*12) + """,12
  837. """)
  838. for case in cases:
  839. tmpobj = {
  840. "url": "https://hhh.com.tw/cases/detail/d/"+str(case["hcase_id"]),
  841. "imgURL": case["cover"],
  842. "title": case["caption"],
  843. "tag": [{"name": tag, "link": "https://hhh.com.tw/search/lists/column/{}-keyword/".format(tag)} for tag in case["tag"].split(',')],
  844. "views": case["viewed"],
  845. "dateSort": str(case["sdate"])
  846. }
  847. x["Content"][3]["Carddata"].append(tmpobj)
  848. # 設計公司簡介
  849. #x["Content"][4]["Carddata"] = []
  850. #cases = db.query("")
  851. """ for case in cases:
  852. tmpobj = {
  853. "imgURL":case["cover"],
  854. "title":case["caption"],
  855. "tag":[{"name": tag, "link": ""} for tag in case["tag"].split(',')],
  856. "views":case["viewed"],
  857. "dateSort":str(case["sdate"])
  858. }
  859. x["Content"][4]["Carddata"].append(tmpobj) """
  860. # print(x)
  861. # print(jData)
  862. """ if not os.path.exists(hhhMBPath):
  863. os.mkdir(hhhMBPath)
  864. with open(hhhMBPath+'/json/designers-' + id + '.json', 'w', encoding='utf-8') as f:
  865. json.dump(jData, f, ensure_ascii=False, indent=4) """
  866. return jData
  867. @app.get("/gencolumn")
  868. def gencolumn(id: str = "6392", sort: str = "new", page: str="1"):
  869. with dataset.connect(connstr) as db:
  870. jData = json.load(open(hhhMBPath+'/json/Columns.json', encoding='utf8'))
  871. records = db.query("""SELECT * FROM _hcolumn c
  872. WHERE c.hcolumn_id = '""" + id + """' AND c.onoff='1' """)
  873. #print(id)
  874. base_c_url="https://hhh.com.tw/columns/lists/"
  875. ctype_sub_dist={
  876. 'hometrends': '居家趨勢',
  877. 'hotrank' : '人氣排行',
  878. 'archdesign' : '建築設計',
  879. 'styleselection' : '風格選店',
  880. 'charitable' : '公益活動',
  881. 'exhibition' : '展演資訊',
  882. 'smallhouse' : '小宅規劃',
  883. 'oldhouse' : '老屋翻新',
  884. 'stylebuild' : '風格營造',
  885. 'color' : '配色佈置',
  886. 'goodhouse' : '好宅特輯',
  887. 'proposal' : '設計提案',
  888. 'news' : '新聞最前線',
  889. 'allocation' : '預算分配',
  890. 'process' : '施工流程',
  891. 'knowledge' : '建材知識',
  892. 'decorating' : '裝潢撇步',
  893. 'fengshui' : '居家風水',
  894. 'housekeeping' : '家事清潔',
  895. 'storageskills' : '收納技巧',
  896. 'renovation' : '改造修繕',
  897. 'retire' : '退休好幸福',
  898. 'furnishings' : '家具家飾',
  899. 'appliances' : '美型家電',
  900. 'recommend' : '推薦廚衛',
  901. 'homegoods' : '居家好物',
  902. 'quality' : '優質建材',
  903. 'brandnews' : '品牌新訊',
  904. 'housingnews' : '房市新聞',
  905. 'specsearch' : '建案特搜',
  906. 'buyandsell' : '買屋賣屋',
  907. 'mortgage' : '房貸稅務',
  908. 'renting' : '租房須知',
  909. }
  910. ctype_sub_dist_converse = {v: k for k, v in ctype_sub_dist.items()}
  911. for x in jData:
  912. icount = 0
  913. c = None
  914. for c in records:
  915. icount += 1
  916. if c != None:
  917. x["Columnsid"] = str(c["hcolumn_id"])
  918. x["Columnstitle"] = c["ctitle"]
  919. x["ColumnsCoverImg"] = c["clogo"]
  920. x["ctype"] = c["ctype"]
  921. x["ctype_sub"] = c["ctype_sub"]
  922. if c["ctype"] == "不限":
  923. x["ctype_link"] = base_c_url+"all-columntypea"
  924. x["ctype_sub_link"] = ""
  925. x["ctype_sub"] = ""
  926. else:
  927. try:
  928. x["ctype_sub_link"] = ctype_sub_dist_converse[c["ctype_sub"]]+"-columntypeb"
  929. except:
  930. x["ctype_sub_link"] = ""
  931. if c["ctype"] == "編輯精選":
  932. x["ctype_link"] = base_c_url+"editorchoose-columntypea"
  933. elif c["ctype"] == "居家設計":
  934. x["ctype_link"] = base_c_url+"housedesign-columntypea"
  935. elif c["ctype"] == "裝修前線":
  936. x["ctype_link"] = base_c_url+"decoration-columntypea"
  937. elif c["ctype"] == "生活PLUS":
  938. x["ctype_link"] = base_c_url+"plus-columntypea"
  939. elif c["ctype"] == "品牌好物":
  940. x["ctype_link"] = base_c_url+"gooditem-columntypea"
  941. elif c["ctype"] == "房市焦點":
  942. x["ctype_link"] = base_c_url+"focus-columntypea"
  943. x["ColumnsDate"] = str(c["sdate"])
  944. x["ColumnsViews"] = str(c["viewed"])
  945. if page == "1":
  946. x["ColumnsContent"] = html.unescape(c["page_content"]).replace('../hhh/',"//www.hhh.com.tw/modules/gs/hhh/").replace('<img',"<img alt='幸福空間專欄' ").replace('../../../uploads/',"//www.hhh.com.tw/uploads/")
  947. tmpTags = []
  948. c["ctag"] = c["ctag"].replace(' ',',')
  949. for tag in c["ctag"].split(','):
  950. tmpTags.append({"Tag": tag})
  951. x["ColumnsTag"] = tmpTags
  952. x["author_inf"] = c["extend_str"]
  953. #相同類別的最新12筆
  954. sql = """SELECT * FROM _hcolumn c
  955. WHERE (c.ctype like '%""" + str(c["ctype"]) + """%' and c.ctype_sub like '%""" + str(c["ctype_sub"]) + """%') and hcolumn_id <> '""" + str(c["hcolumn_id"]) + """' and sdate < now() AND c.onoff='1'
  956. ORDER BY """ + ("sdate" if sort == 'new' else 'viewed') + """ DESC
  957. LIMIT """ + str((int(page) - 1)*12) + """,12
  958. """
  959. if c["ctype"]=='不限':
  960. sql = """SELECT * FROM _hcolumn c
  961. where hcolumn_id <> '""" + str(c["hcolumn_id"]) + """' and sdate < now() AND c.onoff='1'
  962. ORDER BY """ + ("sdate" if sort == 'new' else 'viewed') + """ DESC
  963. LIMIT """ + str((int(page) - 1)*12) + """,12"""
  964. ctypes = db.query(sql)
  965. tmpOtherCols = []
  966. for other in ctypes:
  967. tmpOtherCol = {}
  968. tmpOtherCol["Columnsid"] = str(other["hcolumn_id"])
  969. tmpOtherCol["ColumnsCoverImg"] = other["clogo"]
  970. tmpOtherCol["Views"] = other["viewed"]
  971. tmpOtherCol["Columnstitle"] = other["ctitle"]
  972. tmpTags = []
  973. other["ctag"] = other["ctag"].replace(' ',',')
  974. for tag in other["ctag"].split(','):
  975. tmpTags.append({"Tag": tag})
  976. tmpOtherCol["ColumnsTag"] = tmpTags
  977. tmpOtherCols.append(tmpOtherCol)
  978. x["OtherColumns"] = tmpOtherCols
  979. if icount == 0:
  980. return []
  981. #print(x)
  982. # print(jData)
  983. """ if not os.path.exists(hhhMBPath):
  984. os.mkdir(hhhMBPath)
  985. with open(hhhMBPath+'/json/Columns-' + id + '.json', 'w', encoding='utf-8') as f:
  986. json.dump(jData, f, ensure_ascii=False, indent=4) """
  987. return jData
  988. @app.get("/getColumnAds")
  989. def getColumnAds():
  990. with dataset.connect(connstr) as db:
  991. ads = []
  992. records = db.query("""SELECT adlogo_mobile imgUrl, adlogo DimgUrl, adhref link
  993. FROM _had hh
  994. WHERE adtype LIKE '專欄首大%'
  995. AND hh.onoff='1'
  996. and NOW() BETWEEN start_time AND end_time
  997. ORDER BY cast(SUBSTR(adtype, 4) AS DECIMAL) """)
  998. """ for x in records:
  999. ads.append(x) """
  1000. ads.extend(records)
  1001. rData = json.loads(json.dumps(ads))
  1002. #print(json.dumps(ads))
  1003. return rData
  1004. @app.post("/add_designer_clicks")
  1005. def add_designer_clicks(cid:str):
  1006. with dataset.connect(connstr) as db:
  1007. records = db.query("""UPDATE _hdesigner SET clicks=clicks+1 WHERE hdesigner_id="""+cid)
  1008. db.commit()
  1009. return True
  1010. @app.post("/add_columns_viewed")
  1011. def add_designer_clicks(cid:str):
  1012. with dataset.connect(connstr) as db:
  1013. records = db.query("""UPDATE _hcolumn SET viewed=viewed+1 WHERE hcolumn_id="""+cid)
  1014. db.commit()
  1015. return True
  1016. @app.get("/genjson_new")
  1017. def genjson_new(filename: str = "realtime.json"):
  1018. jData = json.load(open(hhhMBPath+'/json/data_index.json', encoding='utf8'))
  1019. 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 '首八大%' ")
  1020. for x in jData:
  1021. # 頂部輪播區-新刊頭
  1022. if x['id'] == 0:
  1023. records = ExecuteQuery("""SELECT adid,alt_use,adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  1024. WHERE adtype LIKE '新刊頭%'
  1025. AND onoff='1'
  1026. 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))
  1027. ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  1028. x["data"] = []
  1029. for c in records:
  1030. a = {'imgUrl': c['mlo'], 'link': str(
  1031. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp']),'id':c['adid'],'alt':str(c['alt_use'])}
  1032. x["data"].append(a)
  1033. # print(x["data"])
  1034. # 主要輪播區-首八大
  1035. if x['id'] == 1:
  1036. 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
  1037. WHERE adtype LIKE '首八大%'
  1038. AND onoff='1'
  1039. 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))
  1040. ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  1041. x["data"] = []
  1042. for c in records:
  1043. if c['index_char_1']==None:
  1044. c['index_char_1']=''
  1045. if c['index_char_2_1']==None:
  1046. c['index_char_2_1']=''
  1047. if c['index_char_2_2']==None:
  1048. c['index_char_2_2']=''
  1049. if c['index_char_2_3']==None:
  1050. c['index_char_2_3']=''
  1051. a = {'imgUrl': c['mlo'], 'link': str(
  1052. 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'])}
  1053. x["data"].append(a)
  1054. # print(x["data"])
  1055. #tab區塊-最夯設計, 影音實錄, 專欄文章
  1056. if x['id'] == 6:
  1057. x["data"] = []
  1058. #過年後修改
  1059. a = {'tab': '編輯精選', 'data': []}
  1060. records_for_custom = ExecuteQuery("""SELECT hcolumn_id, ctitle,clogo,cdesc,_hcolumn.ctag
  1061. FROM homepage_set
  1062. LEFT JOIN _hcolumn ON mapping_id = hcolumn_id
  1063. WHERE outer_set=8
  1064. AND homepage_set.onoff='Y'
  1065. 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))
  1066. ORDER BY inner_sort limit 8""")
  1067. #加入不重複id
  1068. id_use = []
  1069. for c in records_for_custom:
  1070. id_use.append(c['hcolumn_id'])
  1071. id_len = 8 - len(id_use)
  1072. # print(id_use)
  1073. str_id_use=''
  1074. for k in id_use:
  1075. str_id_use+=' and hcolumn_id!=%s '%k
  1076. # print(str_id_use)
  1077. #加入不重複id sql
  1078. # records = ExecuteQuery("""SELECT ctag,ctitle TT,clogo IMG, CONCAT('/columns/detail/',hcolumn_id,'/') LK, cdesc
  1079. # from _hcolumn
  1080. # WHERE onoff='1' """+str_id_use+"""
  1081. # AND NOW() > sdate
  1082. # ORDER BY hcolumn_id DESC
  1083. # LIMIT 8""")
  1084. records = ExecuteQuery("""SELECT ctag,ctitle TT,clogo IMG, CONCAT('/columns/detail/',hcolumn_id,'/') LK, cdesc
  1085. from _hcolumn
  1086. WHERE onoff='1' """ +str_id_use+"""
  1087. AND NOW() > sdate
  1088. ORDER BY sdate desc,hcolumn_id DESC
  1089. LIMIT """+ str(id_len) +""" """)
  1090. for d in records_for_custom:
  1091. ad = {'imgUrl': d['clogo'], 'link': "/columns/detail/" + str(
  1092. d['hcolumn_id']) + "/", 'title': d['ctitle'], 'ctag':d['ctag'].split(',')}
  1093. a["data"].append(ad)
  1094. for c in records:
  1095. ctag_list=c['ctag'].split(',')
  1096. if len(ctag_list)==1 and ctag_list[0]=='':
  1097. ctag_list=[]
  1098. ad = {'imgUrl': c['IMG'], 'link': c['LK'],
  1099. 'title': c['TT'],'ctag':ctag_list}
  1100. a['data'].append(ad)
  1101. x["data"].append(a)
  1102. a = {'tab': '最夯設計', 'data': []}
  1103. 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
  1104. FROM homepage_set
  1105. LEFT JOIN _hcase ON mapping_id = hcase_id
  1106. left join _hdesigner ON _hcase.hdesigner_id=_hdesigner.hdesigner_id
  1107. WHERE outer_set=2 and _hcase.onoff='1' AND _hdesigner.onoff='1'
  1108. AND homepage_set.onoff='Y'
  1109. 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))
  1110. ORDER BY inner_sort limit 8""")
  1111. #加入不重複id
  1112. id_use = []
  1113. for c in records_for_custom:
  1114. id_use.append(c['hcase_id'])
  1115. id_len = 8 - len(id_use)
  1116. # print(id_use)
  1117. str_id_use=''
  1118. for k in id_use:
  1119. str_id_use+=' and hcase_id!=%s '%k
  1120. records = ExecuteQuery("""SELECT hcase_id,caption TT,tag ,cover IMG, CONCAT('/cases/detail/',hcase_id,'/') LK,_hdesigner.hdesigner_id hid,img_path,title
  1121. from _hcase
  1122. left join _hdesigner ON _hcase.hdesigner_id=_hdesigner.hdesigner_id
  1123. WHERE
  1124. _hcase.onoff='1' AND _hdesigner.onoff='1'
  1125. AND (NOW() > sdate) """+str_id_use+"""
  1126. ORDER BY sdate desc,hcase_id DESC
  1127. LIMIT """+ str(id_len) +""" """)
  1128. for d in records_for_custom:
  1129. ctag_list="、".join(d['tag'].split(',')).split("、")
  1130. if len(ctag_list)==1 and ctag_list[0]=='':
  1131. ctag_list=[]
  1132. ad = {'imgUrl': d['IMG'], 'link': d['LK'],'img_designer':d['img_path'],
  1133. 'title': d['TT'],'ctag':ctag_list,'title_designer':d['title'],'link_designer': "/HHH_NEW/designers/index_designerList.php?cid=" + str(c['hid'])}
  1134. a["data"].append(ad)
  1135. for c in records:
  1136. # print(c['hcase_id'])
  1137. ctag_list="、".join(c['tag'].split(',')).split("、")
  1138. if len(ctag_list)==1 and ctag_list[0]=='':
  1139. ctag_list=[]
  1140. ad = {'imgUrl': c['IMG'], 'link': c['LK'],'img_designer':c['img_path'],
  1141. 'title': c['TT'],'ctag':ctag_list,'title_designer':c['title'],'link_designer': "/HHH_NEW/designers/index_designerList.php?cid=" + str(c['hid'])}
  1142. a['data'].append(ad)
  1143. x["data"].append(a)
  1144. a = {'tab': '最新影音實錄', 'data': []}
  1145. records_for_custom = ExecuteQuery(""" SELECT hvideo_id,title TT,iframe IMG , CONCAT('https://hhh.com.tw/video-post.php?id=',hvideo_id) LK , name
  1146. FROM homepage_set
  1147. LEFT JOIN _hvideo ON mapping_id = hvideo_id
  1148. WHERE outer_set=3
  1149. AND homepage_set.onoff='Y'
  1150. 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))
  1151. ORDER BY inner_sort limit 8""")
  1152. #加入不重複id
  1153. id_use = []
  1154. for c in records_for_custom:
  1155. id_use.append(c['hvideo_id'])
  1156. id_len = 8 - len(id_use)
  1157. #print(id_use)
  1158. str_id_use=''
  1159. for k in id_use:
  1160. str_id_use+=' and hvideo_id!=%s '%k
  1161. records = ExecuteQuery("""SELECT title TT,iframe IMG , CONCAT('https://hhh.com.tw/video-post.php?id=',hvideo_id) LK , name
  1162. from _hvideo where display_datetime < NOW() """+str_id_use+"""
  1163. ORDER BY hvideo_id DESC
  1164. LIMIT """+ str(id_len) +""" """)
  1165. for d in records_for_custom:
  1166. tid = extract.video_id(d['IMG'])
  1167. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  1168. ad = {'imgUrl': timg, 'link': "https://www.youtube.com/watch?v="+str(tid),
  1169. 'description': d['TT']}
  1170. a["data"].append(ad)
  1171. for c in records:
  1172. tid = extract.video_id(c['IMG'])
  1173. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  1174. ad = {'imgUrl': timg, 'link': "https://www.youtube.com/watch?v="+str(tid),
  1175. 'description': c['TT']}
  1176. a['data'].append(ad)
  1177. x["data"].append(a)
  1178. # print(x["data"])
  1179. # 主題企劃區
  1180. if x['id'] == 4:
  1181. records = ExecuteQuery("""SELECT logo lo, CONCAT('/topic/detail/',htopic_id,'/') lk, `desc`, title FROM _htopic
  1182. WHERE onoff = '1'
  1183. ORDER BY htopic_id DESC limit 3""")
  1184. x["data"] = []
  1185. #手機板
  1186. a = {'tab': 'phone', 'data': []}
  1187. for c in records:
  1188. phone = {'imgUrl': c['lo'], 'link': str(
  1189. c['lk']), 'title': c['title']} #'video': 'false', 'description': c['desc'],
  1190. a["data"].append(phone)
  1191. x["data"].append(a)
  1192. #電腦版
  1193. records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  1194. IFNULL(ifnull(ifnull(_hcase.cover,_hcolumn.clogo),_hproduct.cover),_hbrand.logo) J,
  1195. (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
  1196. FROM homepage_set left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  1197. LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'
  1198. LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'
  1199. LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  1200. LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  1201. 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""")
  1202. a = {'tab': 'web', 'data': []}
  1203. for c in records:
  1204. phone = {'imgUrl': c['J'], 'link': str(
  1205. c['url']), 'title': c['caption']} #'video': 'false', 'description': c['desc'],
  1206. a["data"].append(phone)
  1207. x["data"].append(a)
  1208. # print(x["data"])
  1209. # 編輯精選
  1210. # if x['id'] == 4:
  1211. # records = ExecuteQuery("""SELECT hcolumn_id, ctitle, clogo,cdesc
  1212. # FROM homepage_set
  1213. # LEFT JOIN _hcolumn ON mapping_id = hcolumn_id
  1214. # WHERE outer_set=8
  1215. # AND homepage_set.onoff='Y'
  1216. # 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))
  1217. # ORDER BY inner_sort""")
  1218. # x["data"] = []
  1219. # for c in records:
  1220. # a = {'imgUrl': c['clogo'], 'link': "https://hhh.com.tw/columns/detail/" + str(
  1221. # c['hcolumn_id']) + "/", 'title': c['ctitle'], 'video': 'false', 'description': c['cdesc']}
  1222. # x["data"].append(a)
  1223. # print(x["data"])
  1224. # 首列表廣告
  1225. if x['id'] == 3:
  1226. records = ExecuteQuery("""SELECT adid,alt_use,adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  1227. WHERE adtype LIKE '首列表廣告%'
  1228. AND onoff='1'
  1229. 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))
  1230. ORDER BY adtype""")
  1231. x["data"] = []
  1232. for c in records:
  1233. a = {'imgUrl': c['mlo'], 'link': str(
  1234. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp']),'id':c['adid'],'alt':c['alt_use']}
  1235. x["data"].append(a)
  1236. # print(x["data"])
  1237. # 來選好物區
  1238. # if x['id'] == 6:
  1239. # records = ExecuteQuery(
  1240. # "SELECT max_row from outer_site_set WHERE title='來選好貨'")
  1241. # maxrow = 1
  1242. # for c in records:
  1243. # maxrow = c['max_row']
  1244. # 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
  1245. # , (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
  1246. # -- SELECT *
  1247. # FROM homepage_set
  1248. # left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  1249. # LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  1250. # LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  1251. # LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  1252. # WHERE homepage_set.onoff='Y'
  1253. # AND outer_set = (SELECT oss_id from outer_site_set WHERE title='來選好貨')
  1254. # 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))
  1255. # ORDER BY outer_set, inner_sort)
  1256. # UNION
  1257. # (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) + """)
  1258. # LIMIT """ + str(maxrow))
  1259. # x["data"] = []
  1260. # for c in records:
  1261. # #print(c)
  1262. # if c['iframe'] is None:
  1263. # if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  1264. # c['J'] = c['J'].decode('utf8')
  1265. # if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  1266. # c['caption'] = c['caption'].decode('utf8')
  1267. # if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  1268. # c['short_desc'] = c['short_desc'].decode('utf8')
  1269. # a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  1270. # 'description': c['short_desc'], 'video': 'false'}
  1271. # else:
  1272. # tid = extract.video_id(str(c['iframe']))
  1273. # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  1274. # ccaption = ""
  1275. # cdescription = ""
  1276. # if isinstance(c['caption'], bytearray):
  1277. # ccaption = str(c['caption'].decode('utf8'))
  1278. # else:
  1279. # ccaption = str(c['caption'])
  1280. # if c['short_desc'] is not None:
  1281. # if isinstance(c['short_desc'], bytes):
  1282. # cdescription = str(c['short_desc'].decode('utf8'))
  1283. # else:
  1284. # cdescription = str(c['short_desc'])
  1285. # a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  1286. # 'description': cdescription, 'video': tid}
  1287. # x["data"].append(a)
  1288. # # print(x["data"])
  1289. # # 本週推薦
  1290. # if x['id'] == 7:
  1291. # # records = ExecuteQuery(
  1292. # # "SELECT max_row from outer_site_set WHERE title='本週推薦'")
  1293. # maxrow = 8
  1294. # # for c in records:
  1295. # # maxrow = c['max_row']
  1296. # records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  1297. # 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
  1298. # , (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
  1299. # -- SELECT *
  1300. # FROM homepage_set
  1301. # left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  1302. # LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  1303. # LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  1304. # LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  1305. # LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  1306. # WHERE homepage_set.onoff='Y'
  1307. # AND outer_set = (SELECT oss_id from outer_site_set WHERE title='本週推薦')
  1308. # 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))
  1309. # ORDER BY outer_set, inner_sort
  1310. # LIMIT """ + str(maxrow))
  1311. # x["data"] = []
  1312. # for c in records:
  1313. # if c['iframe'] is None:
  1314. # if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  1315. # c['J'] = c['J'].decode('utf8')
  1316. # if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  1317. # c['caption'] = c['caption'].decode('utf8')
  1318. # if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  1319. # c['short_desc'] = c['short_desc'].decode('utf8')
  1320. # a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  1321. # 'description': c['short_desc'], 'video': 'false'}
  1322. # else:
  1323. # tid = extract.video_id(str(c['iframe']))
  1324. # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  1325. # ccaption = ""
  1326. # cdescription = ""
  1327. # if isinstance(c['caption'], bytearray):
  1328. # ccaption = str(c['caption'].decode('utf8'))
  1329. # else:
  1330. # ccaption = str(c['caption'])
  1331. # if c['short_desc'] is not None:
  1332. # if isinstance(c['short_desc'], bytes):
  1333. # cdescription = str(c['short_desc'].decode('utf8'))
  1334. # else:
  1335. # cdescription = str(c['short_desc'])
  1336. # a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  1337. # 'description': cdescription, 'video': tid}
  1338. # x["data"].append(a)
  1339. # # print(x["data"])
  1340. # # 粉絲推薦
  1341. # if x['id'] == 8:
  1342. # records = ExecuteQuery(
  1343. # "SELECT max_row from outer_site_set WHERE title='粉絲推薦'")
  1344. # maxrow = 1
  1345. # for c in records:
  1346. # maxrow = c['max_row']
  1347. # records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title),_hbrand.title) caption ,
  1348. # 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
  1349. # , (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
  1350. # -- SELECT *
  1351. # FROM homepage_set
  1352. # left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  1353. # LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  1354. # LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  1355. # LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  1356. # LEFT JOIN _hbrand ON mapping_id = _hbrand.hbrand_id AND theme_type='brand'
  1357. # WHERE homepage_set.onoff='Y'
  1358. # AND outer_set = (SELECT oss_id from outer_site_set WHERE title='粉絲推薦')
  1359. # 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))
  1360. # ORDER BY outer_set, inner_sort
  1361. # LIMIT """ + str(maxrow))
  1362. # x["data"] = []
  1363. # for c in records:
  1364. # if c['iframe'] is None:
  1365. # if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  1366. # c['J'] = c['J'].decode('utf8')
  1367. # if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  1368. # c['caption'] = c['caption'].decode('utf8')
  1369. # if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  1370. # c['short_desc'] = c['short_desc'].decode('utf8')
  1371. # a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  1372. # 'description': c['short_desc'], 'video': 'false'}
  1373. # else:
  1374. # tid = extract.video_id(str(c['iframe']))
  1375. # timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  1376. # ccaption = ""
  1377. # cdescription = ""
  1378. # if isinstance(c['caption'], bytearray):
  1379. # ccaption = str(c['caption'].decode('utf8'))
  1380. # else:
  1381. # ccaption = str(c['caption'])
  1382. # if c['short_desc'] is not None:
  1383. # if isinstance(c['short_desc'], bytes):
  1384. # cdescription = str(c['short_desc'].decode('utf8'))
  1385. # else:
  1386. # cdescription = str(c['short_desc'])
  1387. # a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  1388. # 'description': cdescription, 'video': tid}
  1389. # x["data"].append(a)
  1390. # 推薦設計師
  1391. if x['id'] == 5:
  1392. records_for_custom = ExecuteQuery(""" SELECT hd.hdesigner_id,hd.title,hd.img_path,hd.name
  1393. FROM homepage_set
  1394. LEFT JOIN _hdesigner hd ON mapping_id = hd.hdesigner_id
  1395. WHERE outer_set=9 AND hd.onoff='1'
  1396. AND homepage_set.onoff='Y'
  1397. 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))
  1398. ORDER BY inner_sort limit 12""")
  1399. #加入不重複id
  1400. id_use = []
  1401. for g in records_for_custom:
  1402. id_use.append(g['hdesigner_id'])
  1403. id_len = 12 - len(id_use)
  1404. print(id_use)
  1405. str_id_use=''
  1406. for k in id_use:
  1407. str_id_use+=' and hdesigner_id!=%s '%k
  1408. records = ExecuteQuery("""SELECT hdesigner_id,title,img_path,name FROM _hdesigner where onoff=1 """+str_id_use +""" order by dorder limit """+ str(id_len) +""" """)
  1409. x["data"] = []
  1410. for d in records_for_custom:
  1411. q = {'imgUrl': d['img_path'],'name': d['title'] ,'designers_name':d['name'],'link': "/HHH_NEW/designers/index_designerList.php?cid=" + str(d['hdesigner_id'])}
  1412. x["data"].append(q)
  1413. for c in records:
  1414. # print(a)
  1415. a = {'imgUrl': c['img_path'],'name': c['title'] ,'designers_name':c['name'],'link': "/HHH_NEW/designers/index_designerList.php?cid=" + str(c['hdesigner_id'])}
  1416. x["data"].append(a)
  1417. #print(x["data"])
  1418. #=======================================================================================================================
  1419. # 加好物API
  1420. if x['id'] == 7:
  1421. records = ExecuteQuery(""" SELECT alt_use,adlogo,adhref FROM _had
  1422. WHERE adtype LIKE '合宜'
  1423. AND onoff='1'
  1424. """) #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))
  1425. #ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)
  1426. # url = 'https://open.shopline.io/v1/products/search'
  1427. # params = {'per_page': 200, 'page': 1,"category_id":"6108deabe15ff9003e5cef08"}
  1428. # headers = {
  1429. # 'accept': 'application/json',
  1430. # 'authorization': 'Bearer '+access_token,
  1431. # 'User-Agent': 'Shopline test'
  1432. # }
  1433. # response = requests.get(url, params=params, headers=headers)
  1434. # use=response.json()
  1435. x["data"] = []
  1436. for d in records:
  1437. q = {'imgUrl': d['adlogo'],'title': d['alt_use'],'link': d['adhref']}
  1438. x["data"].append(q)
  1439. # for i in range(len(use['items'])):
  1440. # for i in range(len(use['items'])):
  1441. # if use['items'][i]['status']=='active':
  1442. # title = use['items'][i]['title_translations']['zh-hant']
  1443. # link = use['items'][i]['link']
  1444. # img = use['items'][i]['medias'][0]['images']['original']['url']
  1445. # a = {'imgUrl': img,'title': title ,'link':'https://shop.hhh.com.tw/products'+link}
  1446. # x["data"].append(a)
  1447. #=======================================================================================================================
  1448. # print(x["data"])
  1449. # if x['id'] == 9:
  1450. # records = ExecuteQuery(
  1451. # "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")
  1452. # for c in records:
  1453. # x['title'] = ""
  1454. # if isinstance(c['T'], bytearray):
  1455. # x['title'] = str(c['T'].decode('utf8'))
  1456. # else:
  1457. # x['title'] = str(c['T'])
  1458. # x['yt'] = extract.video_id(str(c['Y']))
  1459. # print(id)
  1460. # if x['id'] == 10:
  1461. # records = ExecuteQuery(
  1462. # "SELECT all_search_tag ast FROM site_setup")
  1463. # x["data"] = []
  1464. # for c in records:
  1465. # x["data"] = c['ast'].split(',')
  1466. # print(id)
  1467. # print(jData)
  1468. """ if not os.path.exists(hhhMBPath):
  1469. os.mkdir(hhhMBPath)
  1470. with open(hhhMBPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  1471. json.dump(jData, f, ensure_ascii=False, indent=4)
  1472. if not os.path.exists(hhhPCPath):
  1473. os.mkdir(hhhPCPath)
  1474. with open(hhhPCPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  1475. json.dump(jData, f, ensure_ascii=False, indent=4) """
  1476. return jData
  1477. #print(getColumnAds())
  1478. ########
  1479. """ if __name__ == "__main__":
  1480. uvicorn.run(app, host="0.0.0.0", port=8000) """