blogng/blog
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
..
2011-03-21-long-time.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-03-24-school-memories.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-03-26-earth-hour-official-video.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-03-26-firefox.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-04-01-compski-night-firends-and-fun.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-04-05-sharing-the-posterous-way.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-04-19-bed-of-roses.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-04-20-happy.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-04-28-adept.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-05-02-the-story-of-linux.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-05-07-gsoc-2011-i-am-in.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-05-14-welcome-to-acm-courtesy-of-google.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-05-28-hmm-vacation-work-time.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-06-04-distributed-computing.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-06-05-random-reverbations.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-07-19-birthday-food-for-thought.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-08-23-sigsegv.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-08-30-what-you-do-when-you-get-a-free-day.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-09-10-good-to-be-back.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-09-11-nothing-else-matters.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-09-16-crazy.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-10-11-ffmepg-nokia-7210-video-clips.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-10-11-latex-on-the-go.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2011-10-28-falling-slowly.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2012-01-09-arrow-keys-input-in-python.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2012-03-18-progress-bar-in-mercurial-pushpull.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2012-03-29-thamarassery-mountain-pass-wayanad.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2012-11-21-netbsd-chronicles.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2012-11-24-my-perfect-terminal.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2012-12-06-rooting-a-nexus-7.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2012-12-12-name-your-servers.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2013-01-01-a-thank-you-note.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2013-05-03-new-home.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2013-05-28-getting-started-with-rtems-on-archlinux.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2013-05-28-summer-of-code-2013.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2013-06-23-debugging-rtems-with-gdb.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2014-08-16-automatic-log-in-for-act-broadband.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2015-02-21-syslog-on-mac-os-x-cheat-sheet.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2015-03-28-state-of-terminal-2015-edition.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2015-03-29-notes-on-cgo.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2015-06-30-static-site-generators.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2015-08-22-recursion.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2015-12-01-a-random-rant.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2015-12-28-swanthathralokam.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2016-01-14-golang-shorthand-operator-allows-accidental-shadowing-of-variable.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2017-08-02-linux-4.12.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2018-03-08-kuhs.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2018-08-04-freebsd-wifi-configuration.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2019-01-08-recurse-center-day-#-2.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2019-01-20-experiments-in-owning-data.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00
2019-01-23-experiments-in-owning-data:-software.markdown Convert from old categories to tags 2019-01-28 17:16:27 -05:00