def nodeslinktrees(profile, nodes):
    # generate nodes json
    nodesoutput = []
    linksoutput = []
    if hasattr(profile["opts"], "graph"):
        graph = profile["opts"]["graph"]
    else:
        graph = ""
    for node in nodes:
        if graph == "directed":
            title = " (" + str(node["tweetcount"]) + " tweet"
            if node["tweetcount"] != 1:
                title += "s"
            title += ": " + unicode(node["source"]) + " out/" + unicode(node["target"]) + " in)"
        else:
            title = " (" + str(node["tweetcount"]) + " tweet"
            if node["tweetcount"] != 1:
                title += "s"
            title += ")"
        nodesoutput.append({"name": node["name"], 
            "title": unicode(node["name"]) + title})
       
        # generate links
        for targetname in node["links"].iterkeys():
            target = node["links"][targetname]
            if target["count"] >= profile["opts"]["threshold"]:
                linksoutput.append({
                    "source": node["id"], 
                    "target": target["id"], 
                    "value": target["count"]
                })

    return {"profile": profile, "nodes": nodesoutput, "links": linksoutput}
dataset/ETHPy150Open pbinkley/twarc-report/d3output.py/nodeslinktrees/original