
import sys import yaml with open(sys.argv[1]) as fp: data = fp.read() if not data.find("---") == 0: # no head print("NO YAML HEAD FOUND") sys.exit(-1) data = data[3:] head_end = data.find("---") head = data[0:head_end] data = data[head_end+3:] metadata = yaml.safe_load(head) cats = metadata.pop('categories', None) if cats != None: if type(cats) == list: tags = cats elif type(cats) == str: tags = cats.split() tags = list(map(lambda t: t.lower(), tags)) metadata["tags"] = ", ".join(tags) new_data = f"---\n{yaml.dump(metadata, default_flow_style=False)}---{data}" # write it print(f"coverted: categories to tags: {tags} - {sys.argv[1]}") with open(sys.argv[1], "w") as fp: fp.write(new_data) sys.exit(0) if not metadata.get("tags", None): metadata["tags"] = "untagged" new_data = f"---\n{yaml.dump(metadata, default_flow_style=False)}---{data}" print(f"untagged: {sys.argv[1]}") # write it with open(sys.argv[1], "w") as fp: fp.write(new_data) sys.exit(0) print("No changes needed")
16 lines
2.6 KiB
Markdown
16 lines
2.6 KiB
Markdown
---
|
|
author: dhananjayishere
|
|
comments: true
|
|
date: 2011-04-05 15:08:24
|
|
layout: post
|
|
slug: sharing-the-posterous-way
|
|
tags: college
|
|
title: Sharing the posterous way..
|
|
wordpress_id: 48536674
|
|
---
|
|
|
|
For people with no idea, This is our mathematics assignment, shared in
|
|
a posterous way.
|
|
|
|
[](http://dbalan.files.wordpress.com/2011/04/176ee-04042011497.jpg)[](http://dbalan.files.wordpress.com/2011/04/ffd34-04042011498.jpg)[](http://dbalan.files.wordpress.com/2011/04/7c1e6-04042011499.jpg)[](http://dbalan.files.wordpress.com/2011/04/49004-04042011500.jpg)[](http://dbalan.files.wordpress.com/2011/04/98026-04042011501.jpg)[](http://dbalan.files.wordpress.com/2011/04/078bb-04042011502.jpg)[](http://dbalan.files.wordpress.com/2011/04/cdfbb-04042011503.jpg)[](http://dbalan.files.wordpress.com/2011/04/c8ede-04042011504.jpg)[](http://dbalan.files.wordpress.com/2011/04/5141f-04042011505.jpg)[](http://dbalan.files.wordpress.com/2011/04/cbda6-04042011506.jpg)[](http://dbalan.files.wordpress.com/2011/04/d8075-04042011507.jpg)[](http://dbalan.files.wordpress.com/2011/04/acdf3-04042011508.jpg)[](http://dbalan.files.wordpress.com/2011/04/9bf5b-04042011509.jpg)[](http://dbalan.files.wordpress.com/2011/04/2210c-04042011510.jpg)[](http://dbalan.files.wordpress.com/2011/04/52f62-04042011511.jpg)[](http://dbalan.files.wordpress.com/2011/04/63b74-04042011512.jpg)
|