import requests
d={}
with open("/root/mcp-servers/google-workspace/.env") as f:
 for l in f:
  if "=" in l: k,v=l.strip().split("=",1); d[k]=v
r=requests.post("https://oauth2.googleapis.com/token",data={"client_id":d["GOOGLE_CLIENT_ID"],"client_secret":d["GOOGLE_CLIENT_SECRET"],
"refresh_token":d["GOOGLE_REFRESH_TOKEN"],"grant_type":"refresh_token"})
tk=r.json()["access_token"]
h={"Authorization":"Bearer "+tk}
def upload(path,name,mime):
 u="https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable"
 r2=requests.post(u,headers={**h,"Content-Type":"application/json"},json={"name":name})
 loc=r2.headers["Location"]
 with open(path,"rb") as fp:
  r3=requests.put(loc,data=fp,headers={"Content-Type":mime})
 fid=r3.json()["id"]
 requests.post(f"https://www.googleapis.com/drive/v3/files/{fid}/permissions",headers={**h,"Content-Type":"application/json"},json={"role":"reader","type":"anyone"})
 print(f"{name}: https://drive.google.com/file/d/{fid}/view")
 return fid
upload("/tmp/slide113v2.png","Slide113_Oradores_v2.png","image/png")
upload("/tmp/out2.pptx","Sesion BNI Privilegio 24 marzo 2026 v2.pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation")
upload("/tmp/slide113v3.png","Slide113_v3.png","image/png")
upload("/tmp/out7.pptx","Sesion BNI Privilegio 24 marzo 2026 v3.pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation")
upload("/tmp/out8.pptx","Sesion BNI Privilegio 24 marzo 2026 FINAL.pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation")
