添加广告位置刷新脚本

This commit is contained in:
pengtao 2019-09-10 15:17:03 +08:00
parent 17bf55d03e
commit 0ac61402db

View File

@ -4,7 +4,7 @@ from mysql.mmysql import MysqlBase
from prod_config import mysql_promotion_config
from log.mylog import define_logger
import logging
import json
define_logger("/data/logs/reflush_ad.log")
log = logging.getLogger(__name__)
@ -12,11 +12,10 @@ log = logging.getLogger(__name__)
class Reflush_AdInfo():
def __init__(self):
self.myredis = my_redis
self.mysql = MysqlBase(**mysql_promotion_config)
def reflush_ad_via_localtionid(self, locationid):
all = self.myredis.keys()
all = my_redis.keys()
change_key = []
if all:
for one_key in all:
@ -24,20 +23,120 @@ class Reflush_AdInfo():
change_key.append(one_key)
else:
raise Exception("Redis is null!")
ad_list = []
for item in change_key:
pass
temp = my_redis.smembers(item)
for one in temp:
ad_list.append(one)
self.reflush_ad(ad_list)
self.reflush_ad(item)
def reflush_ad(self, adids):
# expirt key via localtionid
for item in adids:
key = f"ad::{item}::info"
my_redis.expire(key, 1)
all_data = []
# add new key
sql = f"""select
a.id,
a.name,
a.ad_num,
a.ad_title,
a.ad_body,
a.ad_image,
a.jump_param,
a.ad_sort,
a.companyid,
a.gameid,
a.channelid,
a.jump_status,
a.ad_property,
b.area,
b.type,
b.mode,
a.locationid
from
(select
id,
name,
ad_num,
ad_title,
ad_body,
ad_image,
jump_param,
ad_sort,
companyid,
gameid,
channelid,
jump_status,
locationid ,
ad_property
from
ad
where
status=1
and in_used=1
and id={item})a ,
(select
id,
area,
type,
mode
from
location) b
where
a.locationid=b.id
"""
data = self.mysql.query(sql)
if data:
for line in data:
item = {}
try:
item['id'], item['name'], item['ad_num'], item['ad_title'], item['ad_body'], item['ad_image'], \
item['jump_param'], item['ad_sort'], item['companyid'], item['gameid'], item['channelid'], \
item['jump_status'], item['ad_property'], item['area'], item['type'], item['mode'], item[
'locationid'] = line
try:
item['x_offset'] = item['area'].split(',')[-2].strip()
except:
item['x_offset'] = 0
try:
item['y_offset'] = item['area'].split(',')[-1].strip().strip(')')
except:
item['y_offset'] = 0
if item.get('jump_param', "") and (item['ad_property'].find("jump_param") == -1):
try:
temp = {}
temp['jump_param'] = item.get('jump_param', "")
if not item['ad_property']:
item['ad_property'] = {}
if not isinstance(item.get('ad_property', {}), dict):
if not item.get('ad_property', {}):
item['ad_property'] = {}.update(temp)
else:
item['ad_property'] = json.loads(
item.get('ad_property', {}).replace("", '"').replace("", '"'))
item['ad_property'].update(temp)
item['ad_property'] = json.dumps(item['ad_property'])
except Exception:
log.error(f"write {item}", exc_info=True)
all_data.append(item)
except Exception:
log.error("split data failed", exc_info=True)
for item in all_data:
my_redis.hmset(f"ad::{item['id']}::info", item)
my_redis.expire(f"ad::{item['id']}::info", 3600 * 24)
def reflush_ad(self, adid):
pass
def main():
pass
cc = Reflush_AdInfo()
cc.reflush_ad_via_localtionid('1016')
if __name__ == "__main__":