def huaweiAgencys(self): try: formdata = { "status": "ALL", "fromRecCount": 0, "maxReqCount": self.maxReqCount, "nsp_svc": "AppPromote.CoreAgent.queryAgentList", "access_token": self.accessToken, "nsp_fmt": "JSON", "nsp_ts": Utils.getMicSecond() } result = self.s.post(self.restUrl, data=formdata, headers=self.headers).text try: jsonresult = json.loads(result, encoding="utf-8") except: return if 'error' in jsonresult: raise HuaweiException(Config.KD_ERROR, [ jsonresult.get('error'), 'methodName: %s' % sys._getframe().f_code.co_name, "resultText: %s" % result, "agencyId: %s" % self.agencyId, "mediaId: %s" % self.mediaId, ]) totalCount = jsonresult.get('totalCount', 0) accounts = jsonresult.get("accounts", []) if 0 == totalCount or 0 == len(accounts): return self.logic.importHuaweiAgencys(jsonresult) except HuaweiException as e: self.log(e.code, e.msg, log_prefix="huawei")
def accountManager(self): try: formdata = { "agentAccountId": 0, "corpName": "", "status": "ALL", "fromRecCount": 0, "maxReqCount": self.maxReqCount, "nsp_svc": "AppPromote.Agent.queryCustomerList", "access_token": self.accessToken, "nsp_fmt": "JSON", "nsp_ts": Utils.getMicSecond() } result = self.s.post(self.restUrl, data=formdata, headers=self.headers).text try: jsonresult = json.loads(result, encoding="utf-8") except: return if 'error' in jsonresult: raise HuaweiException(Config.KD_ERROR, [ jsonresult.get('error'), 'methodName: %s' % sys._getframe().f_code.co_name, "resultText: %s" % result, "agencyId: %s" % self.agencyId, "mediaId: %s" % self.mediaId, ]) # 导入account表 self.logic.importAccount(jsonresult) except HuaweiException as e: self.log(e.code, e.msg, log_prefix="huawei")
def keywordReport(self, startdate, enddate): try: # 获取客户列表 accounts = self.logic.getAccounts() dates = Utils.getDayDeltas(startdate, enddate) for i in accounts: for dateval in dates: startdate = enddate = dateval fromRecCount = 1 # 初始页码1 for c in range(self.maxPageCount): formdata = { "dateFilterStart": startdate, "dateFilterEnd": enddate, "sortField": "totalConsumeSum", "sortType": "DESC", "fromRecCount": fromRecCount, "maxReqCount": 100, "customerAccountId": i['account_id_from_media'], "nsp_svc": "Inapp.Developer.reportPromoAppBySearchKeys", "access_token": self.accessToken, "nsp_fmt": "JSON", "nsp_ts": Utils.getMicSecond() } result = self.s.post(self.restUrl, data=formdata, headers=self.headers).text try: jsonresult = json.loads(result, encoding="utf-8") except: continue if 'error' in jsonresult: raise HuaweiException(Config.KD_ERROR, [ jsonresult.get('error'), 'methodName: %s' % sys._getframe().f_code.co_name, "resultText: %s" % result, "agencyId: %s" % self.agencyId, "mediaId: %s" % self.mediaId, "accountId: %s" % i['account_id_from_media'], "fromRecCount: %s" % fromRecCount, "startdate: %s" % startdate, "enddate: %s" % enddate, ]) totalCount = jsonresult.get('totalCount', 0) taskSearchKeyReportList = jsonresult.get( 'taskSearchKeyReportList', []) if 0 == totalCount: break if 0 == len(taskSearchKeyReportList): break self.logic.importKeywordReport( jsonresult, i['account_id_from_media'], startdate) # print jsonresult # print fromRecCount fromRecCount = fromRecCount + 100 except HuaweiException as e: self.log(e.code, e.msg, log_prefix="huawei")
def keywordDenyList(self): try: # 获取客户列表 accounts = self.logic.getAccounts() for i in accounts: fromRecCount = 0 # 初始页码0 for c in range(self.maxPageCount): formdata = { "fromRecCount": fromRecCount, "maxReqCount": 100, "customerAccountId": i['account_id_from_media'], "nsp_svc": "Inapp.Developer.queryTaskListByNegativeKeys", "access_token": self.accessToken, "nsp_fmt": "JSON", "nsp_ts": Utils.getMicSecond() } result = self.s.post(self.restUrl, data=formdata, headers=self.headers).text try: jsonresult = json.loads(result, encoding="utf-8") except: continue if 'error' in jsonresult: raise HuaweiException(Config.KD_ERROR, [ jsonresult.get('error'), 'methodName: %s' % sys._getframe().f_code.co_name, "resultText: %s" % result, "agencyId: %s" % self.agencyId, "mediaId: %s" % self.mediaId, "accountId: %s" % i['account_id_from_media'], "fromRecCount: %s" % fromRecCount, ]) totalCount = jsonresult.get('totalCount', 0) taskNegativeSearchKeyInfo = jsonresult.get( "taskNegativeSearchKeyInfo", []) if 0 == totalCount: break if 0 == len(taskNegativeSearchKeyInfo): break self.logic.importDenyKeywordList( jsonresult, i['account_id_from_media']) # print jsonresult # print fromRecCount fromRecCount = fromRecCount + 100 except HuaweiException as e: self.log(e.code, e.msg, log_prefix="huawei")
def taskReport(self, startdate, enddate): try: # 获取推广任务列表 tasks = self.logic.getTaskIdList() dates = Utils.getDayDeltas(startdate, enddate) for accountId, taskIdList in tasks.items(): for dateval in dates: startdate = enddate = dateval startdateval = startdate.replace("-", "") enddateval = enddate.replace("-", "") formdata = { "taskIDList": json.dumps(taskIdList), "beginDate": startdateval, "endDate": enddateval, "sortField": "task,time", "sortType": 0, "fromRecCount": 0, "maxReqCount": self.maxReqCount, "customerAccountId": accountId, "nsp_svc": "Inapp.Developer.reportPromoApp", "access_token": self.accessToken, "nsp_fmt": "JSON", "nsp_ts": Utils.getMicSecond() } result = self.s.post(self.restUrl, data=formdata, headers=self.headers).text try: jsonresult = json.loads(result, encoding="utf-8") except: continue if 'error' in jsonresult: raise HuaweiException(Config.KD_ERROR, [ jsonresult.get('error'), 'methodName: %s' % sys._getframe().f_code.co_name, "resultText: %s" % result, "agencyId: %s" % self.agencyId, "mediaId: %s" % self.mediaId, "accountId: %s" % accountId, "taskIDList: %s" % json.dumps(taskIdList), "startdate: %s" % startdate, "enddate: %s" % enddate, ]) # 入库huawei_task表 self.logic.importTaskReport(jsonresult, accountId, startdate) except HuaweiException as e: self.log(e.code, e.msg, log_prefix="huawei")
def dataManager(self, startdate, enddate): try: dates = Utils.getDayDeltas(startdate, enddate) for dateval in dates: startdate = enddate = dateval formdata = { "beginTime": startdate, "endTime": enddate, "fromRecCount": 0, "maxReqCount": self.maxReqCount, "nsp_svc": "AppPromote.Agent.queryReport", "access_token": self.accessToken, "nsp_fmt": "JSON", "nsp_ts": Utils.getMicSecond() } Utils.D(formdata) result = self.s.post(self.restUrl, data=formdata, headers=self.headers).text try: jsonresult = json.loads(result, encoding="utf-8") except: continue if 'error' in jsonresult: raise HuaweiException(Config.KD_ERROR, [ jsonresult.get('error'), 'methodName: %s' % sys._getframe().f_code.co_name, "resultText: %s" % result, "agencyId: %s" % self.agencyId, "mediaId: %s" % self.mediaId, "startdate: %s" % startdate, "enddate: %s" % enddate, ]) # print jsonresult # exit() # 入库huawei_daily_report_account表 self.logic.importDataManager(jsonresult, startdate) time.sleep(Config.HUAWEI_REQUEST_TIME) except HuaweiException as e: self.log(e.code, e.msg, log_prefix="huawei")
def taskList(self, agencyUserId): try: # 获取客户列表 accounts = self.logic.getAccounts() for i in accounts: formdata = { "userID": agencyUserId, "fromRecCount": 0, "maxReqCount": self.maxReqCount, "sortType": 1, "sortField": "modify_time", "customerAccountId": i['account_id_from_media'], "nsp_svc": "Inapp.Developer.queryTaskList", "access_token": self.accessToken, "nsp_fmt": "JSON", "nsp_ts": Utils.getMicSecond() } result = self.s.post(self.restUrl, data=formdata, headers=self.headers).text try: jsonresult = json.loads(result, encoding="utf-8") except: continue if 'error' in jsonresult: raise HuaweiException(Config.KD_ERROR, [ jsonresult.get('error'), 'methodName: %s' % sys._getframe().f_code.co_name, "resultText: %s" % result, "agencyId: %s" % self.agencyId, "mediaId: %s" % self.mediaId, "accountId: %s" % i['account_id_from_media'], "agencyUserId: %s" % agencyUserId, ]) # print jsonresult self.logic.importTaskList(jsonresult, i['account_id_from_media']) except HuaweiException as e: self.log(e.code, e.msg, log_prefix="huawei")