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")
636 B
636 B
author, comments, date, layout, slug, tags, title, wordpress_id
| author | comments | date | layout | slug | tags | title | wordpress_id |
|---|---|---|---|---|---|---|---|
| dhananjayishere | true | 2011-05-28 08:44:00 | post | hmm-vacation-work-time | untagged | Hmm, Vacation (Work) Time. | 54729006 |
Finally my exams are over and I am set free to do watever I like. Now I can start working on my GSoC. People say work is what defines a person, his contributions, however small, is what makes his life worthy of living. I am looking forward to a joyful vacation doing what I like the most, some serious hacking and doing my part of work. A million thanks to the creators of the Summer of code program, and also to my mentor, Steffan. You guys rock.