blogng/blog/2011-04-05-sharing-the-posterous-way.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

16 lines
2.6 KiB
Markdown

---
author: dhananjayishere
comments: true
date: 2011-04-05 15:08:24
layout: post
slug: sharing-the-posterous-way
tags: college
title: Sharing the posterous way..
wordpress_id: 48536674
---
For people with no idea, This is our mathematics assignment, shared in
a posterous way.
[![04042011497](http://dbalan.files.wordpress.com/2011/04/176ee-04042011497.jpg)](http://dbalan.files.wordpress.com/2011/04/176ee-04042011497.jpg)[![04042011498](http://dbalan.files.wordpress.com/2011/04/ffd34-04042011498.jpg)](http://dbalan.files.wordpress.com/2011/04/ffd34-04042011498.jpg)[![04042011499](http://dbalan.files.wordpress.com/2011/04/7c1e6-04042011499.jpg)](http://dbalan.files.wordpress.com/2011/04/7c1e6-04042011499.jpg)[![04042011500](http://dbalan.files.wordpress.com/2011/04/49004-04042011500.jpg)](http://dbalan.files.wordpress.com/2011/04/49004-04042011500.jpg)[![04042011501](http://dbalan.files.wordpress.com/2011/04/98026-04042011501.jpg)](http://dbalan.files.wordpress.com/2011/04/98026-04042011501.jpg)[![04042011502](http://dbalan.files.wordpress.com/2011/04/078bb-04042011502.jpg)](http://dbalan.files.wordpress.com/2011/04/078bb-04042011502.jpg)[![04042011503](http://dbalan.files.wordpress.com/2011/04/cdfbb-04042011503.jpg)](http://dbalan.files.wordpress.com/2011/04/cdfbb-04042011503.jpg)[![04042011504](http://dbalan.files.wordpress.com/2011/04/c8ede-04042011504.jpg)](http://dbalan.files.wordpress.com/2011/04/c8ede-04042011504.jpg)[![04042011505](http://dbalan.files.wordpress.com/2011/04/5141f-04042011505.jpg)](http://dbalan.files.wordpress.com/2011/04/5141f-04042011505.jpg)[![04042011506](http://dbalan.files.wordpress.com/2011/04/cbda6-04042011506.jpg)](http://dbalan.files.wordpress.com/2011/04/cbda6-04042011506.jpg)[![04042011507](http://dbalan.files.wordpress.com/2011/04/d8075-04042011507.jpg)](http://dbalan.files.wordpress.com/2011/04/d8075-04042011507.jpg)[![04042011508](http://dbalan.files.wordpress.com/2011/04/acdf3-04042011508.jpg)](http://dbalan.files.wordpress.com/2011/04/acdf3-04042011508.jpg)[![04042011509](http://dbalan.files.wordpress.com/2011/04/9bf5b-04042011509.jpg)](http://dbalan.files.wordpress.com/2011/04/9bf5b-04042011509.jpg)[![04042011510](http://dbalan.files.wordpress.com/2011/04/2210c-04042011510.jpg)](http://dbalan.files.wordpress.com/2011/04/2210c-04042011510.jpg)[![04042011511](http://dbalan.files.wordpress.com/2011/04/52f62-04042011511.jpg)](http://dbalan.files.wordpress.com/2011/04/52f62-04042011511.jpg)[![04042011512](http://dbalan.files.wordpress.com/2011/04/63b74-04042011512.jpg)](http://dbalan.files.wordpress.com/2011/04/63b74-04042011512.jpg)