Last active
March 26, 2020 15:18
-
-
Save GluTbl/db1322e364914980cf566dfbcd50adef to your computer and use it in GitHub Desktop.
[Facebook backup to VCF] Extract contacts from backup of facebook to .vcf files #facebook
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
import json | |
def readbyte(fileloc: str): | |
in_file = open(fileloc, "rb") # opening for [r]eading as [b]inary | |
data = in_file.read() # if you only wanted to read 512 bytes, do .read(512) | |
in_file.close() | |
return data | |
def get_vcfstring(person): | |
name=person['name'] | |
namesplit=name.split(" ") | |
firststring="" | |
middlestring="" | |
laststring="" | |
for namepoint in namesplit: | |
index=len(namesplit)-1-namesplit.index(namepoint) | |
if(index == 0): | |
firststring=namepoint | |
if index == 1: | |
middlestring=namepoint | |
if index >1: | |
if(laststring==""): | |
laststring=laststring+namepoint | |
else: | |
laststring=laststring+" "+namepoint | |
text1 = "BEGIN:VCARD\n" | |
text2 = "VERSION:3.0\n" | |
text3 = "N:"+firststring+";"+middlestring+";"+laststring+";;\n" | |
text4 = "FN:"+name+"\n" | |
phonearray=person["details"] | |
text5 = "" | |
for phone in phonearray: | |
numberphone=phone["contact_point"] | |
if(text5==""): | |
text5="TEL;TYPE=CELL:"+numberphone+"\n" | |
else: | |
text5=text5+"TEL;TYPE=CELL:"+numberphone+"\n" | |
text6 = "END:VCARD\n" | |
return text1+text2+text3+text4+text5+text6 | |
text= readbyte("C:\\Users\\MyPc\\Desktop\\your_address_books.json") | |
content=text.decode('UTF-8') | |
data=json.loads(content) | |
print(data) | |
data=data['address_book']['address_book'] | |
writable="" | |
for person in data: | |
string=get_vcfstring(person) | |
writable=writable+string | |
print(writable)#You an save this writable in some file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment