标签:xlrd adb 问题 amp nbsp operation sap pac 输入
该脚本文件是一个转化文件,将编辑的Google投广告模板转化成Google批量投放广告的脚本文件,实现批量投放广告,节省投广时间。PS:要与相应的模板结合使用,投广告模板在本人博客的文件中,可以下载。
关于模板的注意事项:
1、模板中的广告系列和广告组名称不能相同
2、如有使用问题可以与我联系
PS:如果有需要用自己的模板进行批量投放的可以进入我的博客与我联系。
1 import xlrd 2 import tkinter as tk 3 4 window = tk.Tk() 5 window.title(‘Google投放广告脚本‘) 6 window.geometry(‘400x300‘) 7 8 l = tk.Label(window,text=‘请输入需要投广的文件名‘,font=(‘Arial‘,12),width=25,height=2) 9 e =tk.Entry(window,show=None) 10 l.pack() 11 e.pack() 12 13 def zhuanhuan(): 14 import os 15 # print(e.get()) 16 cwd =os.getcwd() 17 data_path = cwd +‘\\‘+e.get()+‘.xlsx‘ 18 19 muban = xlrd.open_workbook(data_path) 20 xl = muban.sheets()[0] 21 22 xilie = [] 23 group =[] 24 group_price = [] 25 product_price = [] 26 sku_size = [] 27 for i in range(1,xl.nrows): 28 row = xl.row_values(i) 29 xilie.append(row[0]) 30 group.append(row[1]) 31 group_price.append(row[10]) 32 product_price.append(row[11]) 33 sku_size.append(row[9].split(‘\n‘)) 34 # print(sku_size) 35 36 file_handle = open(e.get()+‘.txt‘,mode=‘w‘) 37 file_handle.write(‘function main (){ \nvar compaign =[‘) 38 for j in range(len(xilie)-1): 39 file_handle.write(‘"‘+xilie[j]+‘"‘+‘,‘) 40 file_handle.write(‘"‘+xilie[len(xilie)-1]+‘"]‘+‘;\nvar group =[‘) 41 for j in range(len(group)-1): 42 file_handle.write(‘"‘+group[j]+‘"‘+‘,‘) 43 file_handle.write(‘"‘+group[len(group)-1]+‘"]‘+‘;\nvar money =[‘) 44 for j in range(len(group_price)-1): 45 file_handle.write(‘"‘+str(group_price[j])+‘"‘+‘,‘) 46 file_handle.write(‘"‘+str(group_price[len(group_price)-1])+‘"]‘+‘;\nfor(var i=0 ;i<compaign.length;i++){\nCreateGroup(compaign[i],group[i],money[i]);\n}\nCreateProduct(group,compaign) ;\nCreateAd(group,compaign);\n}\n‘ 47 ‘function CreateGroup(campaignName,adGroupName,money){\nvar shoppingCampaign = AdsApp.shoppingCampaigns().withCondition("CampaignName = ‘ +"‘"+‘"‘+‘ + campaignName +‘+‘"‘+"‘"+‘").get().next();\n‘ 48 ‘var adGroupOperation = shoppingCampaign.newAdGroupBuilder().withName(adGroupName).withBiddingStrategy(‘+"‘"‘MANUAL_CPC‘"‘"+‘).withStatus(‘+"‘"‘ENABLED‘"‘"+‘).withCpc‘ 49 ‘(money).build();\nreturn true;\n}\nfunction CreateProduct(group,compaign) {\nvar product =[‘) 50 for j in range(len(sku_size)): 51 file_handle.write(str(sku_size[j])+‘,‘) 52 file_handle.write(‘];\nvar product_money =[‘) 53 for j in range(len(product_price)-1): 54 file_handle.write(‘"‘+str(product_price[j])+‘"‘+‘,‘) 55 file_handle.write(‘"‘+str(product_price[len(product_price)-1])+‘"];\nfor(var i =0;i<group.length;i++){\nvar groups = AdsApp.shoppingAdGroups().withCondition("CampaignName = ‘ 56 +"‘"+‘" + compaign[i] + "‘ +"‘"+‘").withCondition("AdGroupName = ‘+"‘"+‘" + group[i] + "‘+"‘"+‘").get().next();\n‘ 57 +‘var child = groups.createRootProductGroup();\nvar root = groups.rootProductGroup();\nfor(var x = 0;x<product[i].length;x++){\nvar a = root.newChild().itemIdBuilder().withValue(product[i][x]).withBid(product_money[i]).build();\n‘ 58 ‘}\n}\n}\nfunction CreateAd(group,compaign) {\nfor(var i =0;i<group.length;i++){\nvar groups = AdsApp.shoppingAdGroups().withCondition("CampaignName = ‘ 59 +"‘"+‘" + compaign[i] + "‘ +"‘"+‘").withCondition("AdGroupName = ‘+"‘"+‘" + group[i] + "‘+"‘"+‘").get().next();\n‘ 60 ‘var adOperation = groups.newAdBuilder().build(); }\n}‘) 61 62 file_handle.close() 63 return None 64 b = tk.Button(window,text=‘转换成脚本文件‘,width=12,height=1,command=zhuanhuan) 65 b.pack() 66 67 window.mainloop()
标签:xlrd adb 问题 amp nbsp operation sap pac 输入
原文地址:https://www.cnblogs.com/chunfang/p/12730397.html