ndrive is a python library that can provide an access to Naver Ndrive. This is not an official Ndrive python API, so some features may not be implemented, yet.
>>> from ndrive import Ndrive
>>> nd = Ndrive()
>>> nd.login("YOUR_ID","YOUR_PASSWORD")
>>> nd.uploadFile("test.txt",'/test.txt',True)
This package is available in PyPI. To install it in your system, use easy_install:
$ easy_install ndrive
Or use pip:
$ pip install ndrive
Or check out developement version:
$ git clone git://github.com/carpedm20/ndrive.git
If you want to start with Ndrive module, you need to login to Ndrive first. Just make a Ndrive object and use login method.
Login:
nd = Ndrive()
nd.login("YOUR_ID","YOUR_PASSWORD")
Then you might want to download a file from your Ndrive, but you might don’t know exact filename in Ndrive directory. Then, you can use getList method to get list of files and directory of given directory.
Don’t forget to put / in front of the Ndrive path, which indicate root directory of Ndrive
Get file and directory List:
nd_list = nd.getList('/', type=3)
print nd_list
If you find a file, then you can download the file to your local directory.
Download:
nd.download('/Picture/flower.png', './flower.png')
Or you can upload a file:
nd.puloadFile('./flower.png','/Picture/flower.png')
You can make a test directory at root directory:
nd.makeDirectory('/test')
and move a file from root to a created test directory:
nd.doMove('/flower.png','/test/flower.png')
This is the information of class and method of ndrive.
Initialize NdriveClient instance.
Using given user information, login to ndrive server and create a session
Parameters: |
|
---|
Usage:
>>> from ndrive import Ndrive
>>> nd = Ndrive()
Send GET request to execute Ndrive API
Parameters: |
|
---|---|
Returns: | metadata when success or False when failed |
Send POST request to execute Ndrive API
Parameters: |
|
---|---|
Returns: | metadata when success or False when failed |
Check status
Check whether it is possible to access Ndrive or not.
Returns: | True when success or False when failed. |
---|
Check whether it is possible to upload a file.
>>> s = nd.checkUpload('~/flower.png','/Picture/flower.png')
Parameters: |
|
---|---|
Returns: | True if possible to upload or False if impossible to upload. |
Make a link of file
If you don’t know resourceno, you’d better use getFileLink.
Parameters: | resourceno – Resource number of a file to create link |
---|---|
Returns: | Shared url or False when failed to share a file |
Delete a file in full_path
>>> nd.delete('/Picture/flower.png')
Parameters: | full_path – The full path to delete the file to, including the file name. |
---|---|
Returns: | True if success to delete the file or False |
Move a file.
>>> nd.doMove('/Picture/flower.png', '/flower.png')
Parameters: |
|
---|---|
Returns: | True if success to move a file or False. |
Get music album list.
Parameters: |
|
---|---|
Returns: | metadata or False |
Metadata: |
|
Download a file.
>>> nd.downloadFile('/Picture/flower.png', '~/flower.png')
Parameters: |
|
---|---|
Returns: | File object |
Get disk space information.
>>> disk_info = nd.getDiskSpace()
Returns: | metadata if success or error message |
---|---|
Metadata: |
|
Get a link of file
>>> file_link = nd.getFileLink('/Picture/flower.png')
Parameters: | full_path – The full path of file to get file link. Path should start and end with ‘/’. |
---|---|
Returns: | Shared url or False if failed to share a file or directory through url |
Get a list of files
>>> nd_list = nd.getList('/', type=3)
>>> print nd_list
Parameters: |
|
---|---|
Returns: | metadata (list of dict) or False when failed to get list |
Metadata: |
|
Get music album list.
Parameters: | tagtype – ? |
---|---|
Returns: | metadata or False |
Metadata: |
|
Get a file property
Parameters: | full_path – The full path to get the file or directory property. |
---|---|
Returns: | metadata if success or False if failed to get property |
Metadata: |
|
Retrieve information about useridx
Parameters: |
|
---|---|
Returns: | True when success or False when failed |
Get a version list of a file or dierectory.
Parameters: |
|
---|---|
Returns: | metadata if succcess or False (failed to get history or there is no history) |
Metadata: |
|
Get a count of version list.
Parameters: | full_path – The full path to get the file or directory property. |
---|---|
Returns: | Integer (number of version lists) or False if failed to get a version list |
Log in Naver and get cookie
>>> s = nd.login("YOUR_ID", "YOUR_PASSWORD")
Parameters: |
|
---|---|
Returns: | True when success to login or False |
Make a directory
>>> nd.makeDirectory('/test')
Parameters: | full_path – The full path to get the directory property. Should be end with ‘/’. |
---|---|
Returns: | True when success to make a directory or False |
Make a share url of directory
>>> nd.makeShareUrl('/Picture/flower.png', PASSWORD)
Upload a file.
>>> nd.put('./flower.png','/Picture/flower.png')
>>> nd.put(open('./flower.png','r'),'/Picture/flower.png')
Parameters: |
|
---|---|
Returns: | True when succcess to upload a file or False |
Set property of a file.
Parameters: |
|
---|---|
Returns: | True when success to set property or False |
Upload a file as Ndrive really do.
>>> nd.uploadFile('~/flower.png','/Picture/flower.png',True)
- POST /CheckStatus.ndrive
- POST /GetDiskSpace.ndrive
- POST /CheckUpload.ndrive
- PUT /FILE_PATH
- POST /GetList.ndrive
- POST /GetWasteInfo.ndrive
- POST /GetDiskSpace.ndrive
nd.uploadFile(‘./flower.png’,’/Picture/flower.png’)
Parameters: |
|
---|
First public preview release.
This Ndrive package is opened under the MIT license. See LISENCE file for a further information.
I’m Kim Tae Hoon, a student who want to be a great developer :)