blogng/blog/2011-06-05-random-reverbations.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

18 lines
2.1 KiB
Markdown

---
author: dhananjayishere
comments: true
date: 2011-06-05 00:23:40
layout: post
slug: random-reverbations
tags: friends
title: Random reverbations.
wordpress_id: 55677606
---
Never underestimate an old hard disk, this was the lesson I learned this morning, So the hard-earned memories,
[![Dsc02841](http://dbalan.files.wordpress.com/2011/06/3f39e-dsc02841.jpg)](http://dbalan.files.wordpress.com/2011/06/3f39e-dsc02841.jpg)[![Dsc00853](http://dbalan.files.wordpress.com/2011/06/fef26-dsc00853.jpg)](http://dbalan.files.wordpress.com/2011/06/fef26-dsc00853.jpg)[![0dsc00853](http://dbalan.files.wordpress.com/2011/06/2eedf-0dsc00853.jpg)](http://dbalan.files.wordpress.com/2011/06/2eedf-0dsc00853.jpg)[![Dsc00952](http://dbalan.files.wordpress.com/2011/06/7cda9-dsc00952.jpg)](http://dbalan.files.wordpress.com/2011/06/7cda9-dsc00952.jpg)[![Dsc00954](http://dbalan.files.wordpress.com/2011/06/4784a-dsc00954.jpg)](http://dbalan.files.wordpress.com/2011/06/4784a-dsc00954.jpg)[![Dsc02780](http://dbalan.files.wordpress.com/2011/06/1b6ee-dsc02780.jpg)](http://dbalan.files.wordpress.com/2011/06/1b6ee-dsc02780.jpg)[![Dsc02782](http://dbalan.files.wordpress.com/2011/06/740d5-dsc02782.jpg)](http://dbalan.files.wordpress.com/2011/06/740d5-dsc02782.jpg)[![Dsc02835](http://dbalan.files.wordpress.com/2011/06/c708e-dsc02835.jpg)](http://dbalan.files.wordpress.com/2011/06/c708e-dsc02835.jpg)[![Dsc02843](http://dbalan.files.wordpress.com/2011/06/a3ab0-dsc02843.jpg)](http://dbalan.files.wordpress.com/2011/06/a3ab0-dsc02843.jpg)[![Image0641](http://dbalan.files.wordpress.com/2011/06/6dc4d-image0641.jpg)](http://dbalan.files.wordpress.com/2011/06/6dc4d-image0641.jpg)[![Image0657](http://dbalan.files.wordpress.com/2011/06/fe2ec-image0657.jpg)](http://dbalan.files.wordpress.com/2011/06/fe2ec-image0657.jpg)[![Ron_22-feb-08_5-20-44_pm](http://dbalan.files.wordpress.com/2011/06/b3371-ron_22-feb-08_5-20-44_pm.jpg)](http://dbalan.files.wordpress.com/2011/06/b3371-ron_22-feb-08_5-20-44_pm.jpg)[![Ron_01-jan-05_3-14-39_pm](http://dbalan.files.wordpress.com/2011/06/0c61d-ron_01-jan-05_3-14-39_pm.jpg)](http://dbalan.files.wordpress.com/2011/06/0c61d-ron_01-jan-05_3-14-39_pm.jpg)