Copy keyframe from action to another while changing bones

I just started using python with Blender, and I’m trying to do something specific.
I have a skeleton with a few bones (Say bone1, bone2, bone3) and an action with a few keyframes (kf1, kf2, kf3).
What I want to do is create a new action where the keyframes are switched around like this: bone1’s first frame becomes bone2’s, bone2’s becomes bone3’s, and bone3’s becomes bone1’s. Same for the second frame.
I’m guessing the pseudocode would look something like:

action1, action2
for frame in animationbone1.action2.frame.locRot = bone2.action1.frame.locRot
bone2.action2.frame.locRot = bone3.action1.frame.locRot
bone3.action2.frame.locRot = bone1.action1.frame.locRot

So, to divide my question in steps, how do I:

  • Create a new action.
  • Access the keyframe (locRot) of a given bone for a given animation.
  • Insert it to another bone in another animation at the same frame.