Skip to content

Instantly share code, notes, and snippets.

@cyb3rsalih
Created May 25, 2024 09:36
Show Gist options
  • Save cyb3rsalih/9cf6d0956749b52e3f07ccb5be10fe51 to your computer and use it in GitHub Desktop.
Save cyb3rsalih/9cf6d0956749b52e3f07ccb5be10fe51 to your computer and use it in GitHub Desktop.
Split vcard files
def split_vcard(file_path, records_per_file):
# vCard dosyasını oku
with open(file_path, "r", encoding="utf-8") as file:
vcard_data = file.read()
# vCard'ları ayır
vcards = vcard_data.split("END:VCARD")
# 'END:VCARD' satırını geri ekle
vcards = [vcard + "END:VCARD" for vcard in vcards if vcard.strip()]
# Her dosyada x tane kayıt olacak şekilde parçalara ayır
parts = [
vcards[i : i + records_per_file]
for i in range(0, len(vcards), records_per_file)
]
# Ayrılmış vCard'ları dosyalara yaz
for i, part in enumerate(parts):
part_file_path = f"at_{i+1}.vcf"
with open(part_file_path, "w", encoding="utf-8") as part_file:
part_file.write("".join(part))
print(f"Part {i+1} saved as {part_file_path}")
# Örnek kullanım
split_vcard("data.vcf", 3000)
# Powered by ChatGPT-4o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment