blogng/blog/2011-04-01-compski-night-firends-and-fun.markdown
Dhananjay Balan 58b20109cf Convert from old categories to tags
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")
2019-01-28 17:16:27 -05:00

13 lines
3.3 KiB
Markdown

---
author: dhananjayishere
comments: true
date: 2011-04-01 06:08:00
layout: post
slug: compski-night-firends-and-fun
tags: friends, trivandrum
title: Compski Night - Friends and Fun
wordpress_id: 48042401
---
[![Me](http://dbalan.files.wordpress.com/2011/04/a9ff5-me.jpg)](http://dbalan.files.wordpress.com/2011/04/a9ff5-me.jpg)[![Img_3093-20](http://dbalan.files.wordpress.com/2011/04/9dafe-img_3093-20.jpg)](http://dbalan.files.wordpress.com/2011/04/9dafe-img_3093-20.jpg)[![Img_3093-17](http://dbalan.files.wordpress.com/2011/04/bfa6a-img_3093-17.jpg)](http://dbalan.files.wordpress.com/2011/04/bfa6a-img_3093-17.jpg)[![Img_3093-0](http://dbalan.files.wordpress.com/2011/04/3bf0a-img_3093-0.jpg)](http://dbalan.files.wordpress.com/2011/04/3bf0a-img_3093-0.jpg)[![Img_3093-2](http://dbalan.files.wordpress.com/2011/04/55f5c-img_3093-2.jpg)](http://dbalan.files.wordpress.com/2011/04/55f5c-img_3093-2.jpg)[![Img_3093-1](http://dbalan.files.wordpress.com/2011/04/2862a-img_3093-1.jpg)](http://dbalan.files.wordpress.com/2011/04/2862a-img_3093-1.jpg)[![Img_3093-3](http://dbalan.files.wordpress.com/2011/04/827eb-img_3093-3.jpg)](http://dbalan.files.wordpress.com/2011/04/827eb-img_3093-3.jpg)[![Img_3093-4](http://dbalan.files.wordpress.com/2011/04/ddc4c-img_3093-4.jpg)](http://dbalan.files.wordpress.com/2011/04/ddc4c-img_3093-4.jpg)[![Img_3093-9](http://dbalan.files.wordpress.com/2011/04/76429-img_3093-9.jpg)](http://dbalan.files.wordpress.com/2011/04/76429-img_3093-9.jpg)[![Img_3093-5](http://dbalan.files.wordpress.com/2011/04/982f5-img_3093-5.jpg)](http://dbalan.files.wordpress.com/2011/04/982f5-img_3093-5.jpg)[![Img_3093-12](http://dbalan.files.wordpress.com/2011/04/b882d-img_3093-12.jpg)](http://dbalan.files.wordpress.com/2011/04/b882d-img_3093-12.jpg)[![Img_3093-10](http://dbalan.files.wordpress.com/2011/04/fa011-img_3093-10.jpg)](http://dbalan.files.wordpress.com/2011/04/fa011-img_3093-10.jpg)[![Img_3093-13](http://dbalan.files.wordpress.com/2011/04/cce9a-img_3093-13.jpg)](http://dbalan.files.wordpress.com/2011/04/cce9a-img_3093-13.jpg)[![Img_3093-21](http://dbalan.files.wordpress.com/2011/04/93fa8-img_3093-21.jpg)](http://dbalan.files.wordpress.com/2011/04/93fa8-img_3093-21.jpg)[![Img_3093-7](http://dbalan.files.wordpress.com/2011/04/3f468-img_3093-7.jpg)](http://dbalan.files.wordpress.com/2011/04/3f468-img_3093-7.jpg)[![Img_3093-8](http://dbalan.files.wordpress.com/2011/04/49cd8-img_3093-8.jpg)](http://dbalan.files.wordpress.com/2011/04/49cd8-img_3093-8.jpg)[![Img_3093-6](http://dbalan.files.wordpress.com/2011/04/5c51e-img_3093-6.jpg)](http://dbalan.files.wordpress.com/2011/04/5c51e-img_3093-6.jpg)[![Img_3093-14](http://dbalan.files.wordpress.com/2011/04/c37ae-img_3093-14.jpg)](http://dbalan.files.wordpress.com/2011/04/c37ae-img_3093-14.jpg)[![Img_3093-15](http://dbalan.files.wordpress.com/2011/04/fd4a4-img_3093-15.jpg)](http://dbalan.files.wordpress.com/2011/04/fd4a4-img_3093-15.jpg)[![Img_3093-16](http://dbalan.files.wordpress.com/2011/04/349f1-img_3093-16.jpg)](http://dbalan.files.wordpress.com/2011/04/349f1-img_3093-16.jpg)[![Img_3093-18](http://dbalan.files.wordpress.com/2011/04/84898-img_3093-18.jpg)](http://dbalan.files.wordpress.com/2011/04/84898-img_3093-18.jpg)[![Img_3093-11](http://dbalan.files.wordpress.com/2011/04/0abbb-img_3093-11.jpg)](http://dbalan.files.wordpress.com/2011/04/0abbb-img_3093-11.jpg)