|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import os |
| 3 | + |
| 4 | +def zero_insert(input_string): |
| 5 | + ''' |
| 6 | + This function get a string as input if input is one digit add a zero |
| 7 | + :param input_string: input digit az string |
| 8 | + :type input_string:str |
| 9 | + :return: modified output as str |
| 10 | + ''' |
| 11 | + if len(input_string)==1: |
| 12 | + return "0"+input_string |
| 13 | + return input_string |
| 14 | + |
| 15 | +def time_convert(input_data): |
| 16 | + ''' |
| 17 | + This function convert input_sec from sec to DD,HH,MM,SS Format |
| 18 | + :param input_string: input time string in sec |
| 19 | + :type input_string:str |
| 20 | + :return: converted time as string |
| 21 | + ''' |
| 22 | + input_sec=input_data |
| 23 | + input_minute=input_sec//60 |
| 24 | + input_sec=int(input_sec-input_minute*60) |
| 25 | + input_hour=input_minute//60 |
| 26 | + input_minute=int(input_minute-input_hour*60) |
| 27 | + input_day=int(input_hour//24) |
| 28 | + input_hour=int(input_hour-input_day*24) |
| 29 | + return zero_insert(str(input_day))+" days, "+zero_insert(str(input_hour))+" hour, "+zero_insert(str(input_minute))+" minutes, "+zero_insert(str(input_sec))+" seconds" |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +def VCF_creator(first_name,last_name,tel_mobile,tel_home,tel_work,email_home,email_work,email_mobile): |
| 34 | + if "VCF_CONVERT" not in os.listdir(): |
| 35 | + os.mkdir("VCF_CONVERT") |
| 36 | + file=open(os.path.join("VCF_CONVERT",last_name+"_"+first_name+".vcf"),"a") |
| 37 | + file.write("BEGIN:VCARD\n") |
| 38 | + file.write("VERSION:3.0\n") |
| 39 | + file.write("N:"+last_name+";"+first_name+";;;"+"\n") |
| 40 | + file.write("FN:" + first_name+" "+last_name + "\n") |
| 41 | + file.write("TEL;type=CELL:"+tel_mobile+"\n") |
| 42 | + file.write("TEL;type=HOME:" + tel_home + "\n") |
| 43 | + file.write("TEL;type=WORK:" + tel_work + "\n") |
| 44 | + file.write("EMAIL;type=INTERNET;type=WORK;type=pref:"+email_work+"\n") |
| 45 | + file.write("EMAIL;type=INTERNET;type=HOME;type=pref:" + email_home + "\n") |
| 46 | + file.write("EMAIL;type=INTERNET;type=CELL;type=pref:" + email_mobile + "\n") |
| 47 | + file.write("END:VCARD") |
| 48 | + file.close() |
| 49 | +def csv_reader(file_name): |
| 50 | + try: |
| 51 | + file=open(file_name,"r") |
| 52 | + unknown_index=0 |
| 53 | + for index,line in enumerate(file): |
| 54 | + if index>0: |
| 55 | + stripped_line=line.strip() |
| 56 | + temp=stripped_line.split(",") |
| 57 | + if len(temp)>8: |
| 58 | + print("[Warning] CSV File Line "+str(index)+" Bad Format") |
| 59 | + continue |
| 60 | + else: |
| 61 | + if len(temp[0])==0 and len(temp[1])==0: |
| 62 | + unknown_index+=1 |
| 63 | + VCF_creator("Unknown ",str(unknown_index),temp[2],temp[3],temp[4],temp[5],temp[6],temp[7]) |
| 64 | + else: |
| 65 | + VCF_creator(temp[0],temp[1],temp[2],temp[3],temp[4],temp[5],temp[6],temp[7]) |
| 66 | + except Exception as e: |
| 67 | + print("[Error] In Reading CSV File") |
| 68 | + |
0 commit comments