diff --git a/get_new_user.py b/get_new_user.py index 743f2f8..fb710c5 100644 --- a/get_new_user.py +++ b/get_new_user.py @@ -31,26 +31,37 @@ class InitFirstAD(): self.hide = 0.8 self.tga.init_tga_write(self.tgaid) + def get_ad_channel(self): + sql =f"""select distinct ad_c""" + def run(self): - begin = self.get_last_times() - users = self.get_new_user(begin) - mark_users = self.hide_user(users) + ad_channels = self.get_ad_channel() + for ad_channel in ad_channels: - log.info(f"get users {len(users)},write {len(mark_users)} to mysql!") - table_name = "newuser" - if mark_users: - for line in mark_users: - try: - temp = {} - temp['gameid'] = self.gameid - temp['channelid'] = self.channelid - temp['accountid'], temp['register_time'], temp['ad_channel'] = line - self.mysql.insert(table_name, temp) - except Exception: - log.error(f"insert {line} to mysql Failed !", exc_info=True) + begin = self.get_last_times(ad_channel) + users = self.get_new_user(begin,ad_channel) + mark_users = self.hide_user(users) - def get_last_times(self): - sql = f"""SELECT create_time FROM newuser ORDER BY create_time DESC LIMIT 1;""" + log.info(f"get users {len(users)},write {len(mark_users)} to mysql!") + table_name = "newuser" + if mark_users: + for line in mark_users: + try: + temp = {} + temp['gameid'] = self.gameid + temp['channelid'] = self.channelid + temp['accountid'], temp['register_time'], temp['ad_channel'] = line + self.mysql.insert(table_name, temp) + except Exception: + log.error(f"insert {line} to mysql Failed !", exc_info=True) + + def get_last_times(self, ad_channel): + sql = f"""SELECT register_time FROM newuser where ad_channel={ad_channel} AND gameid={self.gameid} AND + channelid={self.channelid} + ORDER BY + register_time + DESC + LIMIT 1;""" data = self.mysql.query(sql) try: last_time = data[0][0] @@ -70,7 +81,7 @@ class InitFirstAD(): return None - def get_new_user(self, begin): + def get_new_user(self, begin,ad_channel): rdata = [] sql = f"""SELECT "#account_id", @@ -79,7 +90,8 @@ class InitFirstAD(): FROM v_user_{self.suffix} where - gameid='{self.gameid}' + gameid='{self.gameid}' + AND first_ad_channel='{ad_channel}' AND "account_register_time" BETWEEN timestamp'{begin}' AND timestamp'{self.now}' """ data = self.tga.get_data(sql) if data: