Hints:
Start with a Lagrangian formulation $$ L~:=~\frac{1}{2}(1+e\cos t)^2\dot{q}^2 -V, \qquad V~:=~\frac{w^2}{4}(1+e\cos t) \cos 2(q-t). \tag{1} $$$$ L~:=~\frac{1}{2}(1+e\cos t)^2\dot{q}^2 -V, \qquad V~:=~-\frac{w^2}{4}(1+e\cos t) \cos 2(q-t). \tag{1} $$
Next Legendre transform to obtain the Hamiltonian formulation.