Skip to content

Commit ab7aa3e

Browse files
code uploaded
0 parents  commit ab7aa3e

8 files changed

Lines changed: 205 additions & 0 deletions

File tree

AUTHORS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Core Developers #
2+
3+
----------
4+
- Sepand Haghighi - Sharif University of Technology - ([http://github.com/sepandhaghighi](http://github.com/sepandhaghighi)) ([sepand@qpage.ir](mailto:sepand@qpage.ir))

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Moduland Co
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<div align="center">
2+
<img src="http://moduland.github.io/csv2vcf/images/logo.jpg" height=240px width=320px>
3+
</div>
4+
5+
----------
6+
7+
8+
# CSV2VCF
9+
10+
Convert CSV File To VCF File
11+
12+
13+
----------
14+
15+
By [Moduland Co](http://www.moduland.ir)
16+
17+
----------
18+
19+
20+
</hr>
21+
</hr>
22+
23+
## Installation
24+
### Source Code
25+
- Download [Version 0.1](https://github.com/moduland/csv2vcf/archive/v0.1.zip) or [Latest Source ](https://github.com/Moduland/csv2vcf/archive/master.zip)
26+
27+
- `python3 setup.py install` or `python setup.py install`
28+
29+
30+
## Usage
31+
32+
- Enter contacts in ```contact.csv``` (comma separated)
33+
- Run csv2vcf ```python3 -m csv2vcf``` or ```python -m csv2vcf``` on Mac,Linux or Windows
34+
- Result in ```VCF_CONVERT``` folder
35+
36+
## Input File Format
37+
38+
<div align="center">
39+
<img src="http://moduland.github.io/csv2vcf/images/csv.jpg" height=240px width=320px>
40+
</div>
41+
42+
43+
44+
## Issues & Bug Reports
45+
46+
Just fill an issue and describe it. We'll check it ASAP!
47+
or send an email to [info@moduland.ir](mailto:info@moduland.ir "info@moduland.ir").
48+
49+
50+
## Contribution
51+
52+
You can fork the repository, improve or fix some part of it and then send the pull requests back if you want to see them here. I really appreciate that. ❤️
53+
54+
Remember to write a few tests for your code before sending pull requests.
55+
56+
## Donate to our project
57+
58+
If you feel like our project is important can you please support us?
59+
Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do.
60+
61+
<h3>Bitcoin :</h3>
62+
63+
```1XGr9qbZjBpUQJJSB6WtgBQbDTgrhPLPA```
64+
65+
66+
<h3>Payping (For Iranian citizens) :</h3>
67+
68+
<a href="http://www.payping.net/sepandhaghighi" target="__blank"><img src="http://www.qpage.ir/images/payping.png" height=100px width=100px></a>
69+
70+
## License
71+
<div align="center">
72+
<a href="https://github.com/Moduland/csv2vcf/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"/></a>
73+
<br/>
74+
<a href="http://www.moduland.ir" target="_blank" title="Moduland Website"><img src="http://www.orangetool.ir/images/moduland.jpg" height="128px" width="128px" alt="Moduland Website"></a>
75+
76+
</div>
77+
78+
79+
80+
81+

csv2vcf/VCF.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+

csv2vcf/__main__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
import time
3+
from .VCF import *
4+
if __name__=="__main__":
5+
if "contact.csv" in os.listdir():
6+
time_1=time.perf_counter()
7+
csv_reader("contact.csv")
8+
time_2=time.perf_counter()
9+
delta_time=time_2-time_1
10+
print("VCF Data Generated In " + time_convert(delta_time))
11+
else:
12+
print("[Error] There is no csv input file")

csv2vcf/contact.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
First-Name,Last-Name,Mobile,Home,Work,Email-Home,Email-Work,Email-Mobile

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
time
2+
os
3+

setup.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from distutils.core import setup
2+
setup(
3+
name = 'csv2vcf',
4+
packages = ['csv2vcf'],
5+
version = '0.1',
6+
description = 'Convert CSV to VCF',
7+
long_description="",
8+
author = 'Moduland Co',
9+
author_email = 'info@moduland.ir',
10+
url = 'https://github.com/Moduland/csv2vcf',
11+
download_url = 'https://github.com/Moduland/csv2vcf/tarball/v0.1',
12+
keywords = ['VCF', 'csv', 'contacts','python'],
13+
classifiers = [],
14+
license='MIT',
15+
)

0 commit comments

Comments
 (0)