process_webp_from_db.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import time
  2. import random
  3. import dataset
  4. import os
  5. db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4')
  6. db2 = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4')
  7. table=db2['_had']
  8. cursor=db.query('SELECT adid,adlogo_mobile FROM xoops._had where length(adlogo_mobile_webp)<5 and adlogo_mobile not like "%.gif" order by adid desc limit 30;')
  9. for c in cursor:
  10. # print(c['adid'])
  11. adid=c['adid']
  12. mobile_h=c['adlogo_mobile'].replace('https://images.hhh.com.tw/','/home/hhh-images/')
  13. if '.gif' in mobile_h:
  14. continue
  15. print(mobile_h)
  16. print(os.path.exists(mobile_h))
  17. cmd='cwebp '+mobile_h+" -o "+mobile_h+".webp"
  18. print(cmd)
  19. os.system(cmd)
  20. mobile_h_url=mobile_h.replace('/home/hhh-images/','https://images.hhh.com.tw/')
  21. mobile_h_url+=".webp"
  22. sqlcmd='update _had set adlogo_mobile_webp="'+mobile_h_url+'" where adid="'+str(adid)+'"'
  23. print(sqlcmd)
  24. db2.query(sqlcmd)
  25. # db2.query()
  26. # break