job_top_day_redis.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import json
  2. import time
  3. from datetime import datetime
  4. from collections import defaultdict
  5. import schedule
  6. from loguru import logger
  7. import json
  8. from common.feishu_utils import Feishu
  9. from common.redis import insert_job_data, get_top_data, get_llen_list, get_lrange_list
  10. def jab_day_recommend():
  11. """获取每日每小时top前100数据"""
  12. try:
  13. logger.info(f"开始获取溯源到的数据")
  14. list_task = [{'task:top_data_ks_gjc': '77618314'}, {'task:top_data_dy_gjc':'77618313'}, {'task:top_data_ks_gz':'77618315'}, {'task:top_data_dy_gz':'77618316'}]
  15. for task in list_task:
  16. for key, value in task.items():
  17. count = get_llen_list(key)
  18. if count > 0:
  19. result = []
  20. channel = None
  21. tag_transport_channel = None
  22. top_task = get_lrange_list(key,count)
  23. for top in top_task:
  24. data = json.loads(top)
  25. channel_account_id = data.get("channel_account_id", "")
  26. tag_transport_channel = data.get("tag_transport_channel", "")
  27. channel = data.get("channel", "")
  28. result.append(channel_account_id)
  29. result_string = ",".join(result)
  30. values = [
  31. [
  32. "",
  33. tag_transport_channel,
  34. result_string,
  35. "lev-供给,rol-机器,#str-搬运搜索top视频溯源账号_42,genMod-账号",
  36. value,
  37. "2",
  38. count*3,
  39. "通用-分享到群",
  40. "AI片尾引导",
  41. "zhifeng_emo,sijia",
  42. "",
  43. "",
  44. "AI标题",
  45. "1",
  46. "",
  47. "王雪珂",
  48. channel
  49. ]
  50. ]
  51. Feishu.insert_columns("YqiSsMvvMhr5tCttL7tcRbHTnrd", "d79d48", "ROWS", 1, 2)
  52. time.sleep(0.5)
  53. Feishu.update_values("YqiSsMvvMhr5tCttL7tcRbHTnrd", "d79d48", "A2:Z2", values)
  54. logger.info(f"[+] 成功写入改造飞书表格")
  55. else:
  56. continue
  57. logger.info(f"写入top前100数据成功")
  58. return
  59. except Exception as e:
  60. logger.error(f"写入飞书异常,异常信息{e}")
  61. return
  62. def schedule_tasks():
  63. schedule.every().day.at("00:40").do(jab_day_recommend)
  64. if __name__ == "__main__":
  65. # jab_day_recommend()
  66. schedule_tasks() # 调用任务调度函数
  67. while True:
  68. schedule.run_pending()
  69. time.sleep(1) # 每秒钟检查一次