google的python api客户端的一个简单oo包装器

google_objects的Python项目详细描述


谷歌对象

谷歌的“google api python客户端”库的瘦的python oo包装。 当前支持Python3+

安装

$ pip install google-objects

用法

需要来自google优秀的oauth2lib库的有效google api凭据对象。有关详细信息,请访问here

谷歌硬盘v3

  • 检索驱动器“关于”信息:
fromgoogle_objectsimportDriveClientgdrive=DriveClient(OAUTH2LIB_CREDS)about=gdrive.get_about()print(about.email)print(about.name)# prints link to profile photoprint(about.photo)# ...
  • 按类型列出驱动器中的文件:
files_by_type={'slides':gdrive.list_files('presentation'),'folders':gdrive.list_files('folder'),'spreadsheets':gdrive.list_files('spreadsheets'),}forfileinfiles_by_type['folders']:print(file.id)print(file.name)forfileinfiles_by_type['spreadsheets']:# prints list of parent folder IDsprint(file.parents)# ...
  • 复制并共享文件:
file=gdrive.get_file('FILE_ID')new_file=file.copy('NEW_FILE_NAME',['PARENT_FOLDER_1','PARENT_FOLDER_2'])# allow myfriend@hotmail.com to viewpermission=new_file.add_permission('myfriend@hotmail.com')# print newly created permission informationprint(permission.role,permission.type,permission.email)

谷歌幻灯片v1

  • 检索演示文稿并循环元素:
fromgoogle_objectsimportSlidesClientgslides=SlidesClient(OAUTHLIB_CREDS)presentation=gslides.get_presentation('PRESENTATION_ID')# print slides attributesforslideinpresentation:print(slide.id)forelementinslide:# equivalent to 'for element in presentation.elements()'  print(element.type)# Shape, Table, etc
  • 检查形状中的文本:
shape=presentation.get_element_by_id('SHAPE_ID')forsegmentinshape.text:print(segment.text)
  • 批量更新表中的每个单元格:
# use with to perform batch updates in blockwithpresentationaspres:table=pres.get_element_by_id('TABLE_ID')forcellintable:print(cell.location)# tuple containing cell locationforsegmentincell.text:# update cellsegment.text='UPDATED_VALUE'

谷歌表单v4

  • 检索电子表格并循环工作表:
fromgoogle_objectsimportSheetsClientgsheets=SheetsClient(OAUTHLIB_CREDS)spreadsheet=gsheets.get_spreadsheet('SPREADSHEET_ID')forsheetinspreadsheet:print(sheet.id,sheet.title)
  • 按名称获取工作表并返回其完整的值块:
sheet=spreadsheet['Sheet 1']values=sheet.values()
  • 获取命名范围值块:
named_ranges=spreadsheet.named_ranges('SHEET_NAME!A:C')forrnginnamed_range:values=named_range.get_block()
  • 更新值块:
values=spreadsheet.get_range('SHEET_NAME!A:C')# loop through rowsfori,rowinenumerate(values):values[i]=[1,2,3]print(row)values.update()# you can also use the slice syntax for updating..values[2:5]=[[1,2,4],[4,5,6],[6,7,8]]values.update()
  • 附加到值块:
to_append=[[1,2,3],[4,5,6]]values.append(to_append)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring框架服务单元测试   在Java中遍历hashmaps的hashmap以检索字符串值   如何使用CodeQL检查Java注释是否具有特定属性?   java为什么在Spring Boot中访问此资源而不是登录弹出窗口需要始终获得完全身份验证   处理将多集计数转换为列表的过程   java另一个线性布局,没有出现按钮   eclipse Java映像加载未显示在jar中   java Junit类无法加载基本测试类ApplicationContext   java如何在main中使用my getvalues()方法打印列表   java Sonar,S128:切换案例应该以无条件的“中断”语句结束,而不是继续   java从socket读取字符串错误连接重置错误   java使用新数据刷新任意图表饼图   java通过异步运行lambda访问方法参数   java错误的结果一旦我处理try and catch