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

3.3 KiB

author comments date layout slug tags title wordpress_id
dhananjayishere true 2011-04-01 06:08:00 post compski-night-firends-and-fun friends, trivandrum Compski Night - Friends and Fun 48042401

MeImg_3093-20Img_3093-17Img_3093-0Img_3093-2Img_3093-1Img_3093-3Img_3093-4Img_3093-9Img_3093-5Img_3093-12Img_3093-10Img_3093-13Img_3093-21Img_3093-7Img_3093-8Img_3093-6Img_3093-14Img_3093-15Img_3093-16Img_3093-18Img_3093-11