diff --git a/ad_interface_tornado.py b/ad_interface_tornado.py index 85ee8df..f0f8253 100644 --- a/ad_interface_tornado.py +++ b/ad_interface_tornado.py @@ -11,6 +11,17 @@ import tornado.web import json from myredis import myredis 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' class Adlist(tornado.web.RequestHandler): @@ -23,8 +34,13 @@ def adlist_workflow(input): gameid = input['gameid'] localid = input['localtionid'] key = f"{gameid}::{localid}" - result = myredis.hmgetall(key) - return result + ids = myredis.hmgetall(key) + info = [] + for id in ids: + temp = myredis.hgetall[f"{id}::info"] + info.append(temp) + + return info def getDaySeconds(time_val, incdays): @@ -34,26 +50,56 @@ def getDaySeconds(time_val, incdays): def send_cache_data(): now = datetime.datetime.today().strftime("%Y-%m-%d") - get_data_sql = "select " + 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) -def sendNotify(conf, sendtime): - try: - print('sendNotify start') - params = {'key': 'kingsome'} - secret = 'fc38349c5d084e920925e614c420be9f' - timestamp = time.time() - md5signstr = md5Sign(params, secret, timestamp) - url = conf['notify_url'] + '×tamp=' + str(timestamp) + '&sign=' + md5signstr - req = urllib.request.Request(url) - data = urllib.request.urlopen(req).read() - print('sendNotify end') - except Exception as e: - print('sendNotifu error: ' + str(e)) + # 添加有天数限定的记录 + 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}