import GAM as python module?

1,128 views
Skip to first unread message

Robert Carpenter

unread,
Mar 23, 2012, 7:29:46 PM3/23/12
to google-ap...@googlegroups.com
Is it possible to import GAM as a python module?

I'm not opposed to writing shell scripts to call GAM, but those parts of my brain are a little dusty and poorly-lit these days - it would be nice to be able to script some of these bulk operations in python.

Thanks!
-Robert-

Nicholas Buihner (Dist)

unread,
Mar 27, 2012, 3:49:31 PM3/27/12
to google-ap...@googlegroups.com
I've done this for the last two years with each release of the program. You have to wrap the arg-parsing into a main() func.

gam.py
...func defs...
def main():
      ...huge tree of ifs to parse arguments...
   except:
      ...last couple of lines...

if __name__ == "__main__":
   main()

Then you can import gam and use it's methods or do what I do and write a module and use the oauth and object code from gam. After patching gam.py in this manner, what I do to keep the changes separate so that it's easier to update when new versions come out is to import gam.py into a middle module.

CustomGam.py
from gam import*

def CustomGetInfo(username):
   return ...

For your custom funcs you can just copy and paste the original func from gam.py and then change it to suit your needs. Most of my custom funcs return a dict or False so that I can do error checking without the whole castle crashing down.

MyProject.py
from CustomGam.py import CustomGetInfo

def main():
   ...do stuff...

Nicholas Buihner (Dist)

unread,
Mar 27, 2012, 3:50:39 PM3/27/12
to google-ap...@googlegroups.com
from gam import *

Peter Kolbe

unread,
Aug 31, 2015, 12:32:01 AM8/31/15
to Google Apps Manager, nbui...@hbuhsd.edu
Nicholas, is there any chance you (or someone else) could spell this out a little more for a python noob? I'm trying to increase my python skills while working with GAM.
thx,
-peter

Olinsky, Nicholas

unread,
Aug 31, 2015, 1:32:28 AM8/31/15
to google-ap...@googlegroups.com
I would like to this also
--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/6dc9a085-1416-40a8-8582-91e778ff7fa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Sent from Gmail Mobile

Please note "@sunnyside.wednet.edu" is now "@sunnysideschools.org". Please update your records accordingly.
Reply all
Reply to author
Forward
0 new messages