#! /usr/bin/python3

import json
import os

def addFieldsAndWrite(data, path):
    template = {
        "geo":[
            {"country": "", "region": "", "city": "", "site": ""},
         ],
         "tags": {
             "pub": "", 
             "derelict": "",
             "graffiti": "",
             "rails": "",
             "music": "",
             "bbs": "",
             "msft": "",
             "sk": "",
             "taptu": "",
             "qc": "",
             "3glab": "",
             "scc": "",
             "print": "",
         }
    }
    combined = {**template, **data}
    with open(path, "w") as out:
        print("Writing {}".format(path))
        json.dump(combined, out, indent=2)

for root, dirs, files in os.walk("/home/httpd/nosher.net/docs/images/"):
    for d in dirs:
        if d.find("-") > -1:
            path = (os.path.join(root, d, "metadata.json"))
            data = {}
            try:
                with open(path) as jdata:
                    data = json.load(jdata)
            except FileNotFoundError:
                pass
            addFieldsAndWrite(data, path)

