blogng/blog/2011-05-14-welcome-to-acm-courtesy-of-google.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

27 lines
719 B
Markdown

---
author: dhananjayishere
comments: true
date: 2011-05-14 00:37:00
layout: post
slug: welcome-to-acm-courtesy-of-google
tags: free software, gsoc, thoughts
title: Welcome to ACM, Courtesy of Google
wordpress_id: 52982430
---
So when I opened my mailbox today, this was watinig for me. It may not exactly fall into the type but still kind of first salary to me.
---------- Forwarded message ----------
From: **** <[acmhelp@acm.org](mailto:acmhelp@acm.org)>
Date: 14 May 2011 02:47
Subject: Welcome to ACM, Courtesy of Google
To: [mb.dhananjay@gmail.com](mailto:mb.dhananjay@gmail.com)
Dear Dhananjay Balan:
Welcome to the ACM Community, courtesy of Google! An ACM Student Membership has been created for you,