gur111 icon

Convert iCloud to Google CSV

gur111 | PRO | 06/28/18 08:45:40 AM UTC | 0 ⭐ | 470 👁️ | Never ⏰ | []
Python |

1.8 KB

|

None

|

0 👍

/

0 👎

from __future__ import print_function
import csv
import sys
import re
 
output = ""
 
def print_out(info, end="\n"):
    global output
    output = output+info+end
 
def flush():
    f = open("output.txt", "w")
    f.write(output)
    f.close()
    
 
def normal_phone(num):
    if(num == ""):
        return num
    num = re.sub("[^0-9|\*|\+]","", num)
    if(num[0] != "+" and num[0] != "0" and num[0] != 1 and num[0] != "*"):
        num = "0" + num
    return num
 
with open("test3.csv") as csvfile:
    spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
    i = 0
    exp = re.compile("\([a-z|A-Z|\*]+\)",re.IGNORECASE)
    for row in spamreader:
        i = i+1
        if(len(row) > 0):
            for cur in row:
                cur = cur.split('\n')
                if(len(cur) == 0):
                    print_out("")
                    continue
                
                for phone in cur:
                    #if(phone.index("@") != -1):
                        #continue
                    status = False
                    for res in exp.finditer(phone):
                        status = True
                        if(res.group(0) == " "):
                            continue
                        num = normal_phone(phone[:res.start()-1])
                        type = phone[res.start()+1:len(phone)-1]
                        print_out(type+","+ num, end=",")
                    if(not status):
                        print_out("Mobile,"+normal_phone(phone),end="\n")
                print_out("",end="\n")
                """
                if(i==5303):
                    print(cur)
                    break
            if(i==5303):
                break
        if(i==5303):
            break"""
    print(i)            
    flush()

Comments