Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. from office365.runtime.auth.authentication_context import AuthenticationContext
  2. from office365.sharepoint.client_context import ClientContext
  3.  
  4. username = '@brussels.msf.org'
  5. password = 'secret'
  6. url3 = 'https://msfintl.sharepoint.com/sites/OCB/miniOOPS/Documents/Forms/'
  7.  
  8. tmp = {}
  9. res = {}
  10.  
  11. ctx_auth = AuthenticationContext(url)
  12. # auth
  13. if ctx_auth.acquire_token_for_user(username, password):
  14.     # get context and content
  15.     ctx = ClientContext(url3, ctx_auth)
  16.     web = ctx.web
  17.     ctx.load(web)
  18.     ctx.execute_query()
  19.  
  20.     # site props
  21.     #tmp['title'] = "Web title: {0}".format(web.properties['Name'])
  22.  
  23.     # quering for raccolta1
  24.     list_obj = ctx.web.lists.get_by_title('Bolivia')
  25.     folder = list_obj.root_folder
  26.     ctx.load(folder)
  27.     ctx.execute_query()
  28.  #   tmp['uri'] = "{0}".format(folder.properties["ServerRelativeUrl"])
  29.  
  30.     # getting files
  31.     files = folder.files
  32.     ctx.load(files)
  33.     ctx.execute_query()
  34.     tmp['files'] = []
  35.     for cur_file in files:
  36.         obj = {
  37.             'name': cur_file.properties['Name'],
  38.             'rel': cur_file.properties['ServerRelativeUrl'],
  39.             'uuid': cur_file.properties['UniqueId'],
  40.             'version': cur_file.properties['MajorVersion']
  41.         }
  42.         tmp['files'].append(obj)
  43.     res['msg'] = 'ok'
  44.     res['data'] = tmp
  45. else:
  46.     res['msg'] = 'err'
  47.     res['data'] = ctx_auth.get_last_error()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement