genjson.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. import os
  2. from typing import Optional
  3. from dataset.util import ResultIter
  4. from fastapi import FastAPI
  5. from fastapi.middleware.cors import CORSMiddleware
  6. from pytrends.request import TrendReq
  7. from datetime import tzinfo
  8. import datetime
  9. import mysql.connector
  10. from mysql.connector import Error
  11. import json
  12. from pytube import extract
  13. app = FastAPI()
  14. origins = [
  15. "*"
  16. ]
  17. app.add_middleware(
  18. CORSMiddleware,
  19. allow_origins=origins,
  20. allow_credentials=True,
  21. allow_methods=["*"],
  22. allow_headers=["*"],
  23. )
  24. hhhMBPath = '../hhh-home-mb'
  25. hhhPCPath = '../hhh-home-pc'
  26. def ExecuteQuery(isql):
  27. connection = mysql.connector.connect(
  28. host='hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com',
  29. database='xoops',
  30. user='hhh7796hhh',
  31. password='lYmWsu^ujcA1',
  32. use_unicode=True,
  33. charset='utf8',
  34. collation='utf8_unicode_ci'
  35. )
  36. # connection.set_charset_collation('utf8','utf8_general_ci')
  37. cursor = connection.cursor(dictionary=True)
  38. cursor.execute(isql)
  39. if cursor.rowcount == -1:
  40. return cursor.fetchall()
  41. else:
  42. connection.commit()
  43. return cursor.rowcount
  44. def ExecuteCmd(isql):
  45. connection = mysql.connector.connect(
  46. host='hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com',
  47. database='xoops',
  48. user='hhh7796hhh',
  49. password='lYmWsu^ujcA1'
  50. )
  51. cursor = connection.cursor(dictionary=True)
  52. cursor.execute(isql)
  53. print(cursor.rowcount)
  54. connection.commit()
  55. return None
  56. @app.get("/")
  57. def read_root():
  58. return {"Hello": "World"}
  59. @app.get("/movexoopstostage")
  60. def movexoopstostage(designerid: str = "0", caseid: str = "0"):
  61. ExecuteQuery(
  62. "replace INTO stage._hdesigner SELECT * FROM xoops._hdesigner WHERE hdesigner_id IN ('" + designerid.replace(',', "','")+"');")
  63. ExecuteQuery(
  64. "replace INTO stage._hcase SELECT * FROM xoops._hcase WHERE hcase_id IN ('"+caseid.replace(',', "','")+"');")
  65. ExecuteQuery(
  66. "replace INTO stage._hcase_img SELECT * FROM xoops._hcase_img WHERE hcase_id IN ('"+caseid.replace(',', "','")+"');")
  67. return {"success"}
  68. @app.get("/movepxoopstostage")
  69. def movepxoopstostage(brandid: str = "0", productid: str = "0"):
  70. ExecuteQuery(
  71. "replace INTO stage._hbrand SELECT * FROM xoops._hbrand WHERE hbrand_id IN ('" + brandid.replace(',', "','")+"');")
  72. ExecuteQuery(
  73. "replace INTO stage._hbrand_page SELECT * FROM xoops._hbrand_page WHERE hbrand_id IN ('" + brandid.replace(',', "','")+"');")
  74. ExecuteQuery(
  75. "replace INTO stage._hproduct SELECT * FROM xoops._hproduct WHERE id IN ('"+productid.replace(',', "','")+"');")
  76. ExecuteQuery(
  77. "replace INTO stage._hproduct_img SELECT * FROM xoops._hproduct_img WHERE hproduct_id IN ('"+productid.replace(',', "','")+"');")
  78. return {"success"}
  79. @app.get("/movecxoopstostage")
  80. def movecxoopstostage(columnid: str = "0"):
  81. ExecuteQuery(
  82. "replace INTO stage._hcolumn SELECT * FROM xoops._hcolumn WHERE hcolumn_id IN ('" + columnid.replace(',', "','")+"');")
  83. ExecuteQuery(
  84. "replace INTO stage._hcolumn_img SELECT * FROM xoops._hcolumn_img WHERE hcolumn_id IN ('" + columnid.replace(',', "','")+"');")
  85. ExecuteQuery(
  86. "replace INTO stage._hcolumn_page SELECT * FROM xoops._hcolumn_page WHERE hcolumn_id IN ('" + columnid.replace(',', "','")+"');")
  87. return {"success"}
  88. @app.get("/genjson")
  89. def genjson(filename: str = "realtime.json"):
  90. jData = json.load(open(hhhMBPath+'/json/data.json', encoding='utf8'))
  91. 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 '首八大%' ")
  92. for x in jData:
  93. # 頂部輪播區-新刊頭
  94. if x['id'] == 0:
  95. records = ExecuteQuery("""SELECT adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  96. WHERE adtype LIKE '新刊頭%'
  97. AND onoff='1'
  98. 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))
  99. ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  100. x["data"] = []
  101. for c in records:
  102. a = {'imgUrl': c['mlo'], 'link': str(
  103. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp'])}
  104. x["data"].append(a)
  105. # print(x["data"])
  106. # 主要輪播區-首八大
  107. if x['id'] == 1:
  108. records = ExecuteQuery("""SELECT adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  109. WHERE adtype LIKE '首八大%'
  110. AND onoff='1'
  111. 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))
  112. ORDER BY cast(SUBSTR(adtype,4) AS DECIMAL)""")
  113. x["data"] = []
  114. for c in records:
  115. a = {'imgUrl': c['mlo'], 'link': str(
  116. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp'])}
  117. x["data"].append(a)
  118. # print(x["data"])
  119. #tab區塊-最夯設計, 影音實錄, 專欄文章
  120. if x['id'] == 2:
  121. x["data"] = []
  122. records = ExecuteQuery("""SELECT caption TT ,cover IMG, CONCAT('https://hhh.com.tw/cases/detail/',hcase_id,'/') LK, short_desc txt
  123. from _hcase
  124. left join _hdesigner ON _hcase.hdesigner_id=_hdesigner.hdesigner_id
  125. WHERE
  126. _hcase.onoff='1' AND _hdesigner.onoff='1'
  127. AND(NOW() > sdate)
  128. ORDER BY hcase_id DESC
  129. LIMIT 3""")
  130. a = {'tab': '最夯設計', 'data': []}
  131. for c in records:
  132. ad = {'imgUrl': c['IMG'], 'link': c['LK'],
  133. 'title': c['TT'], 'description': c['txt']}
  134. a['data'].append(ad)
  135. x["data"].append(a)
  136. records = ExecuteQuery("""SELECT title TT,iframe IMG , CONCAT('https://hhh.com.tw/video-post.php?id=',hvideo_id) LK , name
  137. from _hvideo
  138. ORDER BY hvideo_id DESC
  139. LIMIT 4""")
  140. a = {'tab': '影音實錄', 'data': []}
  141. cnt = 0
  142. for c in records:
  143. if cnt == 0:
  144. cnt += 1
  145. continue
  146. tid = extract.video_id(c['IMG'])
  147. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  148. ad = {'imgUrl': timg, 'link': c['LK'],
  149. 'title': c['name'], 'description': c['TT']}
  150. a['data'].append(ad)
  151. x["data"].append(a)
  152. records = ExecuteQuery("""SELECT ctitle TT,clogo IMG, CONCAT('https://hhh.com.tw/columns/detail/',hcolumn_id,'/') LK, cdesc
  153. from _hcolumn
  154. WHERE onoff='1'
  155. AND NOW() > sdate
  156. ORDER BY hcolumn_id DESC
  157. LIMIT 3""")
  158. a = {'tab': '專欄文章', 'data': []}
  159. for c in records:
  160. ad = {'imgUrl': c['IMG'], 'link': c['LK'],
  161. 'title': c['TT'], 'description': c['cdesc']}
  162. a['data'].append(ad)
  163. x["data"].append(a)
  164. # print(x["data"])
  165. # 主題企劃區
  166. if x['id'] == 3:
  167. records = ExecuteQuery("""SELECT logo lo, CONCAT('https://hhh.com.tw/topic/detail/',htopic_id,'/') lk, `desc`, title FROM _htopic
  168. WHERE onoff = '1'
  169. ORDER BY htopic_id DESC limit 3""")
  170. x["data"] = []
  171. for c in records:
  172. a = {'imgUrl': c['lo'], 'link': str(
  173. c['lk']), 'video': 'false', 'description': c['desc'], 'title': c['title']}
  174. x["data"].append(a)
  175. # print(x["data"])
  176. # 編輯精選
  177. if x['id'] == 4:
  178. records = ExecuteQuery("""SELECT hcolumn_id, ctitle, clogo,cdesc
  179. FROM homepage_set
  180. LEFT JOIN _hcolumn ON mapping_id = hcolumn_id
  181. WHERE outer_set=8
  182. AND homepage_set.onoff='Y'
  183. 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))
  184. ORDER BY inner_sort""")
  185. x["data"] = []
  186. for c in records:
  187. a = {'imgUrl': c['clogo'], 'link': "https://hhh.com.tw/columns/detail/" + str(
  188. c['hcolumn_id']) + "/", 'title': c['ctitle'], 'video': 'false', 'description': c['cdesc']}
  189. x["data"].append(a)
  190. # print(x["data"])
  191. # 首列表廣告
  192. if x['id'] == 5:
  193. records = ExecuteQuery("""SELECT adlogo lo,adlogo_mobile mlo, adhref lk, adlogo_mobile_webp lomwebp, adlogo_webp dwebp FROM _had
  194. WHERE adtype LIKE '首列表廣告%'
  195. AND onoff='1'
  196. 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))
  197. ORDER BY adtype""")
  198. x["data"] = []
  199. for c in records:
  200. a = {'imgUrl': c['mlo'], 'link': str(
  201. c['lk']), 'DimgUrl': c['lo'], 'webp': str(c['lomwebp']), 'Dwebp': str(c['dwebp'])}
  202. x["data"].append(a)
  203. # print(x["data"])
  204. # 來選好物區
  205. if x['id'] == 6:
  206. records = ExecuteQuery(
  207. "SELECT max_row from outer_site_set WHERE title='來選好貨'")
  208. maxrow = 1
  209. for c in records:
  210. maxrow = c['max_row']
  211. 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
  212. , (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
  213. -- SELECT *
  214. FROM homepage_set
  215. left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  216. LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  217. LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  218. LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  219. WHERE homepage_set.onoff='Y'
  220. AND outer_set = (SELECT oss_id from outer_site_set WHERE title='來選好貨')
  221. 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))
  222. ORDER BY outer_set, inner_sort)
  223. UNION
  224. (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) + """)
  225. LIMIT """ + str(maxrow))
  226. x["data"] = []
  227. for c in records:
  228. print(c)
  229. if c['iframe'] is None:
  230. if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  231. c['J'] = c['J'].decode('utf8')
  232. if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  233. c['caption'] = c['caption'].decode('utf8')
  234. if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  235. c['short_desc'] = c['short_desc'].decode('utf8')
  236. a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  237. 'description': c['short_desc'], 'video': 'false'}
  238. else:
  239. tid = extract.video_id(str(c['iframe']))
  240. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  241. ccaption = ""
  242. cdescription = ""
  243. if isinstance(c['caption'], bytearray):
  244. ccaption = str(c['caption'].decode('utf8'))
  245. else:
  246. ccaption = str(c['caption'])
  247. if c['short_desc'] is not None:
  248. if isinstance(c['short_desc'], bytes):
  249. cdescription = str(c['short_desc'].decode('utf8'))
  250. else:
  251. cdescription = str(c['short_desc'])
  252. a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  253. 'description': cdescription, 'video': tid}
  254. x["data"].append(a)
  255. # print(x["data"])
  256. # 本週推薦
  257. if x['id'] == 7:
  258. records = ExecuteQuery(
  259. "SELECT max_row from outer_site_set WHERE title='本週推薦'")
  260. maxrow = 1
  261. for c in records:
  262. maxrow = c['max_row']
  263. records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title) caption , IFNULL(ifnull(_hcase.cover,_hcolumn.clogo),_hproduct.cover) J, iframe , IFNULL(ifnull(ifnull(_hcase.short_desc,_hcolumn.cdesc),_hproduct.descr),_hvideo.`desc`) short_desc
  264. , (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
  265. -- SELECT *
  266. FROM homepage_set
  267. left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  268. LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  269. LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  270. LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  271. WHERE homepage_set.onoff='Y'
  272. AND outer_set = (SELECT oss_id from outer_site_set WHERE title='本週推薦')
  273. 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))
  274. ORDER BY outer_set, inner_sort
  275. LIMIT """ + str(maxrow))
  276. x["data"] = []
  277. for c in records:
  278. if c['iframe'] is None:
  279. if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  280. c['J'] = c['J'].decode('utf8')
  281. if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  282. c['caption'] = c['caption'].decode('utf8')
  283. if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  284. c['short_desc'] = c['short_desc'].decode('utf8')
  285. a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  286. 'description': c['short_desc'], 'video': 'false'}
  287. else:
  288. tid = extract.video_id(str(c['iframe']))
  289. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  290. ccaption = ""
  291. cdescription = ""
  292. if isinstance(c['caption'], bytearray):
  293. ccaption = str(c['caption'].decode('utf8'))
  294. else:
  295. ccaption = str(c['caption'])
  296. if c['short_desc'] is not None:
  297. if isinstance(c['short_desc'], bytes):
  298. cdescription = str(c['short_desc'].decode('utf8'))
  299. else:
  300. cdescription = str(c['short_desc'])
  301. a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  302. 'description': cdescription, 'video': tid}
  303. x["data"].append(a)
  304. # print(x["data"])
  305. # 粉絲推薦
  306. if x['id'] == 8:
  307. records = ExecuteQuery(
  308. "SELECT max_row from outer_site_set WHERE title='粉絲推薦'")
  309. maxrow = 1
  310. for c in records:
  311. maxrow = c['max_row']
  312. records = ExecuteQuery("""SELECT theme_type, mapping_id, IFNULL(ifnull(ifnull(_hcase.caption,_hcolumn.ctitle),_hproduct.name),_hvideo.title) caption , IFNULL(ifnull(_hcase.cover,_hcolumn.clogo),_hproduct.cover) J, iframe , IFNULL(ifnull(ifnull(_hcase.short_desc,_hcolumn.cdesc),_hproduct.descr),_hvideo.`desc`) short_desc
  313. , (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
  314. -- SELECT *
  315. FROM homepage_set
  316. left join _hcase ON _hcase.hcase_id=homepage_set.mapping_id AND theme_type='case'-- AND _hcase.onoff = '1'
  317. LEFT JOIN _hproduct ON mapping_id = _hproduct.id AND theme_type='product'-- AND _hproduct.onoff = '1'
  318. LEFT JOIN _hcolumn ON mapping_id = _hcolumn.hcolumn_id AND theme_type='column'-- AND _hcolumn.onoff = '1'
  319. LEFT JOIN _hvideo ON mapping_id = _hvideo.hvideo_id AND theme_type='video'
  320. WHERE homepage_set.onoff='Y'
  321. AND outer_set = (SELECT oss_id from outer_site_set WHERE title='粉絲推薦')
  322. 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))
  323. ORDER BY outer_set, inner_sort
  324. LIMIT """ + str(maxrow))
  325. x["data"] = []
  326. for c in records:
  327. if c['iframe'] is None:
  328. if isinstance(c['J'], bytearray) or isinstance(c['J'], bytes):
  329. c['J'] = c['J'].decode('utf8')
  330. if isinstance(c['caption'], bytearray) or isinstance(c['caption'], bytes):
  331. c['caption'] = c['caption'].decode('utf8')
  332. if isinstance(c['short_desc'], bytearray) or isinstance(c['short_desc'], bytes):
  333. c['short_desc'] = c['short_desc'].decode('utf8')
  334. a = {'imgUrl': c['J'], 'link': c['url'], 'title': c['caption'],
  335. 'description': c['short_desc'], 'video': 'false'}
  336. else:
  337. tid = extract.video_id(str(c['iframe']))
  338. timg = "https://img.youtube.com/vi/" + tid+"/hqdefault.jpg"
  339. ccaption = ""
  340. cdescription = ""
  341. if isinstance(c['caption'], bytearray):
  342. ccaption = str(c['caption'].decode('utf8'))
  343. else:
  344. ccaption = str(c['caption'])
  345. if c['short_desc'] is not None:
  346. if isinstance(c['short_desc'], bytes):
  347. cdescription = str(c['short_desc'].decode('utf8'))
  348. else:
  349. cdescription = str(c['short_desc'])
  350. a = {'imgUrl': timg, 'link': c['url'], 'title': ccaption,
  351. 'description': cdescription, 'video': tid}
  352. x["data"].append(a)
  353. # print(x["data"])
  354. if x['id'] == 9:
  355. records = ExecuteQuery(
  356. "SELECT id, (case when youtube_title = '' OR youtube_title IS NULL then (SELECT title FROM _hvideo 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 ORDER BY hvideo_id DESC LIMIT 1) ELSE youtube_id end) Y FROM site_setup")
  357. for c in records:
  358. x['title'] = ""
  359. if isinstance(c['T'], bytearray):
  360. x['title'] = str(c['T'].decode('utf8'))
  361. else:
  362. x['title'] = str(c['T'])
  363. x['yt'] = extract.video_id(str(c['Y']))
  364. # print(id)
  365. if x['id'] == 10:
  366. records = ExecuteQuery(
  367. "SELECT all_search_tag ast FROM site_setup")
  368. x["data"] = []
  369. for c in records:
  370. x["data"] = c['ast'].split(',')
  371. # print(id)
  372. # print(jData)
  373. if not os.path.exists(hhhMBPath):
  374. os.mkdir(hhhMBPath)
  375. with open(hhhMBPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  376. json.dump(jData, f, ensure_ascii=False, indent=4)
  377. if not os.path.exists(hhhPCPath):
  378. os.mkdir(hhhPCPath)
  379. with open(hhhPCPath+'/json/' + filename, 'w', encoding='utf-8') as f:
  380. json.dump(jData, f, ensure_ascii=False, indent=4)
  381. return jData
  382. """ if __name__ == "__main__":
  383. uvicorn.run(app, host="0.0.0.0", port=8000) """