Beispiel #1
0
 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")
Beispiel #2
0
 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")
Beispiel #3
0
    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")