bobbydurrett / copyfiletosharepoint Goto Github PK
View Code? Open in Web Editor NEWPython console program to copy a file from my Windows laptop to my corporate SharePoint site
License: MIT License
Python console program to copy a file from my Windows laptop to my corporate SharePoint site
License: MIT License
copyfiletosharepoint is my attempt to build a python script that will copy a file from my work Windows laptop up to my corporate SharePoint site on Office 365. It is based on https://github.com/microsoftgraph/python-sample-console-app python-sample-console-app is a console app that does several things including uploading a file from my windows laptop to OneDrive. So I hacked out all of the code except the part that uploaded the file and I modified it to work with SharePoint. As far as licencing goes I'm fine with releasing this under the MIT license just as Microsoft did. Hopefully I filled out the copyright info correctly. Some of the code is verbatim MS code from python-sample-console-app. But I put a number of hours of work into other code that is all mine. Anyway, feel free to use this any way you please but there is no warranty. Use at your own risk. See the file LICENSE. To get this to work you need to create an application at the site https://apps.dev.microsoft.com/#/appList The "Application Id" is the same as CLIENT_ID in config.py. It needs to be a Native application in the Platforms section. I gave it the following Delegated Permissions, not all of which are necessarily needed: Files.ReadWrite.All People.Read Sites.ReadWrite.All User.Read User.ReadBasic.All User.ReadWrite You probably need the following Python packages from pip: pyperclip requests adal I'm currently using Python 3.6.6 32-bit on Windows 7. The program has an amusing way of authenticating against SharePoint. Here is how you would upload two files in a row, only authenticating once: session = False session = upload_one_file(base_path,folder_path,file_name,session) session = upload_one_file(base_path,folder_path,file_name2,session) The variable session holds the session information after you login the first time. You want to save it in a variable for subsequent calls to upload_one_file so you don't have to login each time. To login it pops up a web browser that asks for a Code on a Device Login page. In Windows 7 you just right-click and it pastes in your code. Then click Continue. Then choose your SharePoint account just as you would logging into SharePoint on the web. After you have done all of these steps the console program starts running. Here is what the output looks like uploading file_name and file_name2 using the code listed above. C:\copyfiletosharepoint>python test.py The code BEM6USL6D has been copied to your clipboard, and your web browser is opening https://microsoft.com/devicelogin. Paste the code to sign in. <Response [200]> bytes returned: 464 Deleting file <Response [404]> Uploading file bytes 0-292332/292333 Checking in file <Response [204]> <Response [200]> bytes returned: 464 Deleting file <Response [404]> Uploading file bytes 0-292332/292333 Checking in file <Response [204]> Bobby Durrett
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.