Jared 2 år sedan
förälder
incheckning
0dff03962b
1 ändrade filer med 84 tillägg och 0 borttagningar
  1. 84 0
      choozmo/ads_csv2_csv.py

+ 84 - 0
choozmo/ads_csv2_csv.py

@@ -0,0 +1,84 @@
+import csv
+import sys
+import codecs
+with codecs.open('C:\\Users\\jared\\Downloads\\search.csv', 'r','utf-16') as csvfile:
+    spamreader = csv.reader(csvfile, delimiter='\t', quotechar='|')
+
+    kwdict={}
+    addict={}
+    head=True
+    for row in spamreader:
+        if head:
+            head=False
+            continue
+        ll=len(row)
+        campaign=row[0]
+        adgroup=row[19]
+        kw=row[47]
+        if len(kw)>0:
+            print(campaign)
+            print(adgroup)
+            if kwdict.get(adgroup) is None:
+                kwdict[adgroup]=[]
+            if addict.get(adgroup) is None:
+                addict[adgroup]=[]
+
+            kwdict[adgroup].append(kw)
+        for i in range(66,104,2):
+            hline=row[i]
+            if len(hline)>0:
+                addict[adgroup].append(hline)
+
+fw=codecs.open('c:/tmp/gads.csv','w','utf-8')
+fw.write("活動,群組,關鍵字,廣告")
+for k,v in kwdict.items():
+    kwlen=len(v)
+    adlen=len(addict[k])
+    totlen=max(kwlen,adlen)
+    for i in range(totlen):
+        try:
+            kw=v[i]
+        except:
+            kw=' '
+        try:
+            ad=addict[k][i]
+        except:
+            ad=' '
+        data=campaign+"\t"+k+"\t"+kw+"\t"+ad+"\n"
+        fw.write(data)
+
+
+fw.close()
+
+#    for k,v in addict.items():
+#        print('rectangle '+k+'_ad'+' {')
+#        print('card '+k+'廣告'+' [')
+
+#        for itm in v:
+#            print(itm)
+#        print(']')
+#        print('}')
+
+
+
+
+#        print(campaign+' -[#black]-> '+k+'_ad')
+
+
+#    print(kwdict)
+#    print(addict)
+
+
+
+
+
+#    for row in spamreader:
+#        ll=len(row)
+#
+#        for i in range(ll):
+#            print(i)
+#            print(row[i])
+#        break
+    
+#
+#    sys.exit()