# -*- coding: utf-8 -*- import os import json import time import hashlib import urllib.request import tornado.ioloop import tornado.web import json from myredis.myredis import my_redis import datetime from mysql.mmysql import MysqlBase from config import mysql_promotion_config from log.mylog import define_logger import logging mydb = MysqlBase(**mysql_promotion_config) define_logger("/data/logs/make_ad_cache.log") log = logging.getLogger(__name__) BEGIN = '1999-01-01' END = '3000-01-01' def send_cache_data(): now = datetime.datetime.today().strftime("%Y-%m-%d") all = [] # 添加无天数限定的记录 get_full_data = f"select id,name,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort,companyid,locationid,gameid from ad where begin_time='{BEGIN}' or end_time='{END}'" full_data = mydb.query(get_full_data) if full_data: for line in full_data: if line: item = {} try: item['id'], item['name'], item['ad_num'], item['ad_title'], item['ad_body'], item['ad_image'], item['ad_url'], \ item['ad_sort'], item['companyid'], item['locationid'], item['gameid'] = line all.append(item) except Exception: log.error("split data failed", exc_info=True) # 添加有天数限定的记录 get_data_sql = f"select id,name,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort,companyid,locationid,gameid from ad where '{now}'>begin_time and '{now}'