Okay, I had this bookmarked before, and now I can't find it. What variable sets a planet's primary and secondary focus? (WOW its been along time since I've been on here.
This is what you are looking for (AIInterface.cpp):
int IssueChangeFocusOrder(int planet_id, FocusType focus_type, bool primary)
Not sure how to determine what focus a planet currently has, though... it probably has not been exposed to python yet. Anyway, if you want to code AI modules, it will help you a lot if you familiarise yourself with AIInterface.cpp (in fo/AI) as well as all .cpp files in fo/python. Are you working on resource management? Keep us informed, please!