DEV Community

Cover image for CSV to Markdown Generator
Scott Gordon
Scott Gordon

Posted on

2

CSV to Markdown Generator

# csv_to_markdown.py
#   This program imports a comma separated list of values
#   for clients of a gym. It then processes the information
#   into a markdown file.
# by: Scott Gordon

def main():
    # Import client information.
    infile = open("LocationOfCSVFile.csv", "r")
    outfile = open("ExportLocationOfMarkdown.md", "w")

    # Convert the information to a markdown friendly format.
    # This modify header and variables as you see fit, but make sure it matches .csv
    print("First Name | Last Name | Birthday | City | State | Zipcode | Email | Phone", file=outfile)
    print("----- | ----- | ----- | ----- | ----- | ----- | ------ | -----", file=outfile)

    # Loop line by line extracting variables for the fields
    # Export the file as a markdown file.
    for line in infile.readlines():
        split_line = line.split(",")
        fname = split_line[0]
        lname = split_line[1]
        bday = split_line[2]
        city = split_line[3]
        state = split_line[4]
        zipcode = split_line[5]
        email = split_line[6]
        phone = split_line[7]
        print(f"{fname} | {lname} | {bday} | {city} | {state} | {zipcode} | {email} | {phone}",
              file=outfile, end="")

    infile.close()
    outfile.close()


main()
Enter fullscreen mode Exit fullscreen mode

Photo by Mika Baumeister on Unsplash

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay