Skip to content

socraticDevBlog/frontmatter_to_csv

Repository files navigation

Python Docker YAML Linux macOS Windows Microsoft Excel readble CSV

frontmatter_to_csv

simple python script that parses files' frontmatter section and output files' metadata as a machine-readable CSV file

a Frontmatter is a YAML style key-value pair section delimited by triple-dashed-lines above and under:

example of a simple frontmatter section:

---
date: 2024-02-03
topics:
  - data
  - intelligence
---

Authors

Installation

Install my-project with pipenv

  pipenv install

Run Locally

start a python shell within your virtual environment

  pipenv shell

execute script

  python main.py "example_files"

Demo

as long as a frontmatter section exists in a file of any type, metadata_to_csv will parse its metadata and print out a CSV file containing the metadata of all files in this directory

CSV machine readable file generated from files' metadata

author,country,file_type
Kid Kubernetes,USA,null
Jacques Derrida,France,markdown
Heraclitus,ionia,null
max,canada,txt
gunther,germany,python

from collection of files in a directory

a python file:

---
author: gunther
country: germany
file_type: python
---

print("hello world")
...

a markdown file:

---
author: Jacques Derrida
country: France
file_type: markdown
---

# the pharmakon hon hon

## first section

...

a yaml file:

---
author: Kid Kubernetes
country: USA
file_type: yaml
---
kind: ultraNice
api: basic/v1
grocery:
  - milk
  - bread
  - yogurt

a txt file:

---
author: max
country: canada
file_type: txt
---

abcdefg

Run in Docker container

you don't want to bother setting your local machine up with Python, you can run the script in a Docker container

  1. edit docker.sh variables to fit your situation
  2. execute script
chmod +x docker.sh

./docker.sh
  1. retrieve your metadata dataset in a csv file in this directory: metadata.csv

About

will parse any file frontmatter and output a machine readable CSV file containing files metadata

Topics

Resources

License

Stars

Watchers

Forks