Jared 2 år sedan
förälder
incheckning
a31dda65a9
1 ändrade filer med 78 tillägg och 0 borttagningar
  1. 78 0
      choozmo/ads_csv.py

+ 78 - 0
choozmo/ads_csv.py

@@ -0,0 +1,78 @@
+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)
+
+
+    for k,v in kwdict.items():
+        print('rectangle '+k+'_kw'+' {')
+        print('card '+k+'關鍵字'+' [')
+        for itm in v:
+            print(itm)
+        print(']')
+        print('}')
+
+    for k,v in addict.items():
+        print('rectangle '+k+'_ad'+' {')
+        print('card '+k+'廣告'+' [')
+
+        for itm in v:
+            print(itm)
+        print(']')
+        print('}')
+
+    for k,v in kwdict.items():
+        print(k+' -[#black]-- '+k+'_ad')
+        print(k+' -[#black]-- '+k+'_kw')
+
+    for k,v in kwdict.items():
+        print(campaign+' -[#black]-> '+k)
+
+
+
+#        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()