How can I apply a basic material to an object using python in cycles render?
The super-simple example is

import bpy

def mission1(obj):
    mat = bpy.data.materials.new("bacon")
    mat.diffuse_color=(0.8,0,1)

    obj.data.materials[0] = mat

obj = bpy.context.active_object
mission1(obj)


If you need to actually create and rig nodes, update your question with a screenshot of nodes you have manually created and if I have time I'll cobble together some code to build a matching node tree using python.