def CheckKeyWordByAccount(self, accountInfo,keywordlist):
        strUserName = accountInfo[0]
        if accountInfo[0] == "baidu-短语商家2140114":
            self.password = "******"
        else:
            self.password = "******"
        keyworkClient = sms_v3_KeywordService()
        keyworkClient.setUsername(accountInfo[0])
        keyworkClient.setPassword(self.password)
        keyworkClient.setToken("796fbec57ff499a2894ea4ac0b579c1b")

        adGroupClient = sms_v3_AdgroupService()
        adGroupClient.setUsername(accountInfo[0])
        adGroupClient.setPassword(self.password)
        adGroupClient.setToken("796fbec57ff499a2894ea4ac0b579c1b")

        indexNum = 0
        repeategroupNum = 0
        usefulgroupNum = 0

        groupIdDict = dict()
        for keywordinfo in keywordlist:
            if(cmp(keywordinfo, '') == 0):
                continue
            textList = keywordinfo.split('\t')

            impression=float(textList[10])
            click=float(textList[11])
            tmp=textList[12].split('\\')[0]
            cost=float(tmp)
            tmpp=[impression,click,cost]
            if groupIdDict.has_key(textList[4]):
                groupIdDict[textList[4]] = self.add_list(groupIdDict[textList[4]],tmpp)
                continue
            else:
                groupIdDict[textList[4]] = tmpp
        return groupIdDict
Esempio n. 2
0
    def CheckKeyWord(self, accountInfo):
        newAccount = list()
        for item in accountInfo:
            newAccount.append(str(item).encode('utf-8'))

        strUserName = newAccount[0]
        if newAccount[0] == "baidu-短语商家2140114":
            self.password = "******"
        else:
            self.password = "******"
        keyworkClient = sms_v3_KeywordService()
        keyworkClient.setUsername(newAccount[0])
        keyworkClient.setPassword(self.password)
        keyworkClient.setToken("796fbec57ff499a2894ea4ac0b579c1b")
        #keyworkClient.setTarget(newAccount[0])

        adGroupClient = sms_v3_AdgroupService()
        adGroupClient.setUsername(newAccount[0])
        adGroupClient.setPassword(self.password)
        adGroupClient.setToken("796fbec57ff499a2894ea4ac0b579c1b")
        #adGroupClient.setTarget(accountInfo[0])

        indexNum = 0
        repeategroupNum = 0
        usefulgroupNum = 0
        for keywordinfo in self.keywordshow:
            if(cmp(keywordinfo, '') == 0):
                continue
            textList = keywordinfo.split('\t')
            if self.groupIdDict.has_key(textList[5]):
                repeategroupNum += 1
                continue
            else:
                self.groupIdDict[textList[5]] = 0
            #检查推广单元的状态
            adGroupIds = {"adgroupIds":[textList[5]]}
            adgroupInfo = adGroupClient.getAdgroupByAdgroupId(adGroupIds)

            tempInt = 0
            if adgroupInfo is not None and adgroupInfo['header'] is not None and adgroupInfo['header']['status'] != 0:
                print "response:"
                print adgroupInfo
                continue

            while(adgroupInfo is None or adgroupInfo['body'] is None or adgroupInfo['body']['adgroupTypes'] is None or (len(adgroupInfo['body']['adgroupTypes']) == 0) ):
                time.sleep(0.1)
                adgroupInfo = adGroupClient.getAdgroupByAdgroupId(adGroupIds)
                print adgroupInfo
                if(tempInt >2):
                    break
                tempInt += 1
            if(tempInt > 2):
                usefulgroupNum += 1
                continue
            if adgroupInfo['body']['adgroupTypes'][0]['status'] != 31:
                usefulgroupNum += 1
                continue

            keywordReq = {"keywordIds":[textList[7]]}
            time.sleep(0.05)
            resKeyWordInfo = keyworkClient.getKeywordByKeywordId(keywordReq)
            checkNum = 0
            while( resKeyWordInfo is None or resKeyWordInfo['body'] is None or resKeyWordInfo['body']['keywordTypes'] is None or len(resKeyWordInfo['body']['keywordTypes']) == 0):
                if(checkNum > 3):
                    break
                time.sleep(0.1)
                resKeyWordInfo = keyworkClient.getKeywordByKeywordId(keywordReq)
                checkNum += 1
            if(checkNum > 3):
                continue
            keywords = resKeyWordInfo['body']['keywordTypes']

            for keyword in keywords:
                print keyword
                indexNum += 1
                print 'repeatekeywords', repeategroupNum, 'adgroup unuseful', usefulgroupNum,'urlindex:', indexNum
                try:
                    strUrlPc = keyword['pcDestinationUrl']
                except Exception, e:
                    continue

                strUrl = strUrlPc
                if( strUrl != None and cmp(strUrl, "") != 0):
                    self.pcurlNum += 1
                    resTemp = ''
                    resTemp += newAccount[0] + '\t'
                    resTemp += textList[3] + '\t'
                    resTemp += textList[4] + '\t'
                    resTemp += textList[6] + '\t'
                    resTemp += keyword['keyword'].encode('utf-8') +'\t'
                    resTemp += 'pc' + '\t'
                    resTemp += keyword['pcDestinationUrl'].encode('utf-8')
                   # self.urlList.append(resTemp)
                try:
                    strUrlMobile = keyword['mobileDestinationUrl']
                except Exception, e:
                    continue

                strUrl = strUrlMobile
                if(strUrl != None and cmp(strUrl, "") != 0):
                    self.mobileurlNum += 1
                    resTemp = ''
                    resTemp += newAccount[0] + '\t'
                    resTemp += textList[3] + '\t'
                    resTemp += textList[4] + '\t'
                    resTemp += textList[6] + '\t'
                    resTemp += keyword['keyword'].encode('utf-8') + '\t'
                    resTemp += 'mobile' + '\t'
                    resTemp += keyword['mobileDestinationUrl'].encode('utf-8')
                    # self.urlList.append(resTemp)
                if(cmp(strUrlPc, "") == 0 and cmp(strUrlMobile, "") == 0):
                    resTemp = ''
                    resTemp += newAccount[0] + '\t'
                    resTemp += textList[3] + '\t'
                    resTemp += textList[4] + '\t'
                    resTemp += textList[6] + '\t'
                    resTemp += keyword['keyword'].encode('utf-8') + '\t'
                    resTemp += 'null' + '\t'
                    resTemp += "null"
                    # self.urlList.append(resTemp)
                self.FuncCheckUrl(resTemp)