-
-
Notifications
You must be signed in to change notification settings - Fork 505
Added a script that can conver vcf contacts file to excle, which then you can edit as you wish to edit in excle #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shaun2006
wants to merge
2
commits into
wasmerio:main
Choose a base branch
from
shaun2006:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # VCF to Excel Converter | ||
|
|
||
| A simple Python script to convert a `.vcf` (vCard) file into an Excel `.xlsx` file. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Python 3.x | ||
| - pandas | ||
| - openpyxl | ||
|
|
||
| Install required packages: | ||
|
|
||
| ```bash | ||
| pip install pandas openpyxl | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| Run the script from the command line: | ||
|
|
||
| ```bash | ||
| python vcf_to_excel.py input.vcf -o output.xlsx | ||
| ``` | ||
|
|
||
| If you do not provide the `-o` option, the script will automatically create an Excel file with the same name as the input file. | ||
|
|
||
| Example: | ||
|
|
||
| ```bash | ||
| python vcf_to_excel.py contacts.vcf | ||
| ``` | ||
|
|
||
| This will create: | ||
|
|
||
| ``` | ||
| contacts.xlsx | ||
| ``` | ||
|
|
||
| ## Extracted Fields | ||
|
|
||
| The script extracts the following fields from the VCF file: | ||
|
|
||
| - Full Name | ||
| - Phone Numbers | ||
| - Emails | ||
| - Organization | ||
| - Address | ||
|
|
||
| ## Notes | ||
|
|
||
| - Multiple phone numbers and emails are combined into a single cell separated by commas. | ||
| - The input file must be a valid `.vcf` file. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| BEGIN:VCARD | ||
| VERSION:3.0 | ||
| N:Doe;John;;; | ||
| FN:John Doe | ||
| ORG:Example.com Inc.; | ||
| TITLE:Imaginary test person | ||
| EMAIL;type=INTERNET;type=WORK;type=pref:johnDoe@example.org | ||
| TEL;type=WORK;type=pref:+1 617 555 1212 | ||
| TEL;type=WORK:+1 (617) 555-1234 | ||
| TEL;type=CELL:+1 781 555 1212 | ||
| TEL;type=HOME:+1 202 555 1212 | ||
| item1.ADR;type=WORK:;;2 Enterprise Avenue;Worktown;NY;01111;USA | ||
| item1.X-ABADR:us | ||
| item2.ADR;type=HOME;type=pref:;;3 Acacia Avenue;Hoemtown;MA;02222;USA | ||
| item2.X-ABADR:us | ||
| NOTE:John Doe has a long and varied history\, being documented on more police files that anyone else. Reports of his death are alas numerous. | ||
| item3.URL;type=pref:http\://www.example/com/doe | ||
| item3.X-ABLabel:_$!<HomePage>!$_ | ||
| item4.URL:http\://www.example.com/Joe/foaf.df | ||
| item4.X-ABLabel:FOAF | ||
| item5.X-ABRELATEDNAMES;type=pref:Jane Doe | ||
| item5.X-ABLabel:_$!<Friend>!$_ | ||
| CATEGORIES:Work,Test group | ||
| X-ABUID:5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE\:ABPerson | ||
| END:VCARD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import pandas as pd | ||
| import argparse | ||
|
|
||
|
|
||
| def parse_vcf(vcf_file): | ||
| contacts = [] | ||
|
|
||
| with open(vcf_file, 'r', encoding='utf-8') as file: | ||
| contact = {} | ||
|
|
||
| for line in file: | ||
| line = line.strip() | ||
|
|
||
| if line.startswith("BEGIN:VCARD"): | ||
| contact = {} | ||
|
|
||
| elif line.startswith("FN:"): | ||
| contact["Full Name"] = line.replace("FN:", "") | ||
|
|
||
| elif line.startswith("TEL"): | ||
| phone = line.split(":")[-1] | ||
| contact.setdefault("Phone Numbers", []).append(phone) | ||
|
|
||
| elif line.startswith("EMAIL"): | ||
| email = line.split(":")[-1] | ||
| contact.setdefault("Emails", []).append(email) | ||
|
|
||
| elif line.startswith("ORG:"): | ||
| contact["Organization"] = line.replace("ORG:", "") | ||
|
|
||
| elif line.startswith("ADR"): | ||
| address = line.split(":")[-1].replace(";", " ") | ||
| contact["Address"] = address | ||
|
|
||
| elif line.startswith("END:VCARD"): | ||
| contact["Phone Numbers"] = ", ".join(contact.get("Phone Numbers", [])) | ||
| contact["Emails"] = ", ".join(contact.get("Emails", [])) | ||
| contacts.append(contact) | ||
|
|
||
| return contacts | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Convert VCF to Excel") | ||
| parser.add_argument("input", help="Input VCF file") | ||
| parser.add_argument("-o", "--output", help="Output Excel file") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| input_file = args.input | ||
| output_file = args.output if args.output else input_file.replace(".vcf", ".xlsx") | ||
|
|
||
| contacts = parse_vcf(input_file) | ||
| df = pd.DataFrame(contacts) | ||
| df.to_excel(output_file, index=False) | ||
|
|
||
| print(f"✅ Conversion complete! Saved as {output_file}") | ||
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.