This is my use case: I want to make a proper file index out of my Google contact list. (For an Obsidian "vault".) Exporting the and converting it to was easy, but there, I am stuck:
I was able to split the big table with a ".CSV ", but if I want convert the hundreds of files created in that split from .CSV to .MD, then the only way I can do this is by hand. That is not desirable.
Any idea how I can fix this?
Thank you! :)
Assistant
To efficiently convert your Google Contacts .CSV files into individual .MD () files for your vault, you can automate the process using a script. Here’s a step-by-step solution:
1.Export Google Contacts to .CSV
You've already done this, so move on to processing the .CSV files.
2.Organize the .CSV Files
Place all your split .CSV files in a single folder to streamline processing.
3.Automate CSV-to-MD Conversion
Use a script inPythonor another scripting language to read the .CSV files and convert them to .MD files. Here's a Python solution:
Python Script for CSV-to-MD Conversion
Install Python if you don't already have it.
Install the required library:bashCopypip install pandas
Use this script:pythonCopyimportosimportpandasaspd# Input folder containing CSV filesinput_folder ='path_to_your_csv_folder'# Output folder for filesoutput_folder ='path_to_your_md_folder'os.makedirs(output_folder, exist_ok=True)forcsv_fileinos.listdir(input_folder):ifcsv_file.endswith('.csv'):
file_path = os.path.join(input_folder, csv_file)
df = pd.read_csv(file_path)# Iterate through each row in the CSVforindex, rowindf.iterrows():# Generate the file name for Markdownfile_name =f"{row.get('Name',f'Contact_{index}')}.md"
file_path_md = os.path.join(output_folder, file_name)# Create Markdown contentmd_content =f"#{row.get('Name','Unnamed Contact')}\n\n"forcolumn, valueinrow.items():
md_content +=f"{column}:{value}\n\n"# Write the content to a Markdown filewithopen(file_path_md,'w', encoding='utf-8')asmd_file:
md_file.write(md_content)print("Conversion complete! Check the output folder.")
for csv_file in os.listdir(input_folder):
if '):
file_path = os.path.join(input_folder, csv_file)
df = pd.read_csv(file_path)
code
# Iterate through each row in the CSV
for index, row in df.iterrows():
# Generate the file name for <REDACTED>
file_name = f"{row.get('Name', f'Contact_{index}')}.md"
file_path_md = os.path.join(output_folder, file_name)
# Create Markdown content
md_content = f"# {row.get('Name', 'Unnamed Contact')}\n\n"
for column, value in <REDACTED>():
md_content += f"**{column}:** {value}\n\n"
# Write the content to a <REDACTED> file
with open(file_path_md, 'w', encoding='utf-8') as md_file:
md_file.write(md_content)
print("Conversion complete! Check the output folder.")
4.Adapt the Script to Your Needs
Replacepath_to_your_csv_folderwith the actual folder containing your .CSV files.
Replacepath_to_your_md_folderwith the desired folder for your .MD files.
Replacepath_to_your_csv_folderwith the actual folder containing your .CSV files.
Replacepath_to_your_md_folderwith the desired folder for your .MD files.
5.Run the Script
Save the script asconvert_csv_to_md.py.
Run it in your terminal or command prompt:bashCopypython convert_csv_to_md.py
Once the .MD files are generated, move them into your vault.
This script automates the entire process, saving you from manually creating hundreds of files. If you need further help customizing the script, feel free to ask!