gur111

Convert iCloud to Google CSV

Jun 28th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. from __future__ import print_function
  2. import csv
  3. import sys
  4. import re
  5.  
  6. output = ""
  7.  
  8. def print_out(info, end="\n"):
  9.     global output
  10.     output = output+info+end
  11.  
  12. def flush():
  13.     f = open("output.txt", "w")
  14.     f.write(output)
  15.     f.close()
  16.    
  17.  
  18. def normal_phone(num):
  19.     if(num == ""):
  20.         return num
  21.     num = re.sub("[^0-9|\*|\+]","", num)
  22.     if(num[0] != "+" and num[0] != "0" and num[0] != 1 and num[0] != "*"):
  23.         num = "0" + num
  24.     return num
  25.  
  26. with open("test3.csv") as csvfile:
  27.     spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
  28.     i = 0
  29.     exp = re.compile("\([a-z|A-Z|\*]+\)",re.IGNORECASE)
  30.     for row in spamreader:
  31.         i = i+1
  32.         if(len(row) > 0):
  33.             for cur in row:
  34.                 cur = cur.split('\n')
  35.                 if(len(cur) == 0):
  36.                     print_out("")
  37.                     continue
  38.                
  39.                 for phone in cur:
  40.                     #if(phone.index("@") != -1):
  41.                         #continue
  42.                     status = False
  43.                     for res in exp.finditer(phone):
  44.                         status = True
  45.                         if(res.group(0) == " "):
  46.                             continue
  47.                         num = normal_phone(phone[:res.start()-1])
  48.                         type = phone[res.start()+1:len(phone)-1]
  49.                         print_out(type+","+ num, end=",")
  50.                     if(not status):
  51.                         print_out("Mobile,"+normal_phone(phone),end="\n")
  52.                 print_out("",end="\n")
  53.                 """
  54.                if(i==5303):
  55.                    print(cur)
  56.                    break
  57.            if(i==5303):
  58.                break
  59.        if(i==5303):
  60.            break"""
  61.     print(i)            
  62.     flush()
Add Comment
Please, Sign In to add comment