gen_json_designers_list_data.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ####################################use for all ,not use in crontab
  2. import os
  3. from typing import Optional
  4. from dataset.util import ResultIter
  5. from datetime import tzinfo
  6. import datetime
  7. import mysql.connector
  8. from mysql.connector import Error
  9. import dataset
  10. import json
  11. from pytube import extract
  12. import requests
  13. import json
  14. hhhMBPath = '../hhh-home-mb'
  15. hhhPCPath = '../hhh-home-pc'
  16. #connstr = 'mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4'
  17. #2022/12/13 change
  18. connstr = 'mysql://hhh7796hhh:lYmWsu^ujcA1@ec2-3-35-26-49.ap-northeast-2.compute.amazonaws.com:3306/xoops?charset=utf8mb4'
  19. """ db = dataset.connect(
  20. 'mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4') """
  21. # charset='utf8',
  22. # collation='utf8_unicode_ci'
  23. #2022/12/13 change
  24. connobj = {
  25. 'host': 'ec2-3-35-26-49.ap-northeast-2.compute.amazonaws.com',
  26. 'database': 'xoops',
  27. 'user': 'hhh7796hhh',
  28. 'password': 'lYmWsu^ujcA1',
  29. 'use_unicode': True
  30. #'charset': 'utf8',
  31. #'collation': 'utf8_unicode_ci'
  32. }
  33. #connobj = {
  34. # 'host': 'hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com',
  35. #'database': 'xoops',
  36. #'user': 'hhh7796hhh',
  37. #'password': 'lYmWsu^ujcA1',
  38. #'use_unicode': True
  39. ##'charset': 'utf8',
  40. ##'collation': 'utf8_unicode_ci'
  41. #}
  42. # def ExecuteQuery(isql):
  43. # with mysql.connector.connect(**connobj) as connection :
  44. # with connection.cursor(dictionary=True) as cursor:
  45. # # connection.set_charset_collation('utf8','utf8_general_ci')
  46. # #cursor = connection.cursor(dictionary=True)
  47. # cursor.execute(isql)
  48. # return cursor.fetchall()
  49. # records = ExecuteQuery("SELECT hcolumn_id FROM _hcolumn where onoff=1")
  50. # list_use = []
  51. # for i in records:
  52. # list_use.append(i['hcolumn_id'])
  53. # #print(list_use)
  54. # for j in list_use:
  55. while True:
  56. try:
  57. a=requests.get('https://m3.hhh.com.tw:18673/designer_search?page=1&page_size=18&order_by=recommend')
  58. break
  59. except:
  60. print('bad:',j)
  61. time.sleep(5)
  62. d=a.json()
  63. print(d)
  64. with open('../designers/lists/json/designers_lists_data.json','w+',encoding="utf-8") as f:
  65. json.dump(d, f)
  66. cmd="""curl -X POST "https://api.cloudflare.com/client/v4/zones/8cb58022ad5743cfd9f088d5e3a261eb/purge_cache" -H "X-Auth-Email: web.dept.hhh@gmail.com" -H "X-Auth-Key:63e51d9a1638d66afcbfc3320aabec52304de" -H "Content-Type: application/json" --data '{"files":["https://hhh.com.tw/hhh-test/designers/lists/json/designers_lists_data.json"]}'"""
  67. print(cmd)
  68. os.system(cmd)
  69. #if str(j)=='5':
  70. # break