Skip to content

Commit

Permalink
restructure a bit and listfolder implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Jan 1, 2017
1 parent 78797a5 commit 9ffc53a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
47 changes: 11 additions & 36 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,42 @@
This text does not appear on pypi or github. It is a comment.
==============================================================================
collective.foo
pycloud - A Python API client for pCloud
==============================================================================

Tell me what your product does
This Python libbrar

Features
--------

- Can be bullet points
- Can be used as a library
- Comes with a command line script


Examples
--------

This add-on can be seen in action at the following sites:
- Is there a page on the internet where everybody can see the features?
>>> from pycloud import PyCloud
>>> pc = PyCloud('[email protected]', 'SecretPassword')
>>> pc.listfolder()


Documentation
-------------

Full documentation for end users can be found in the "docs" folder, and is also available online at http://docs.plone.org/foo/bar


Translations
------------

This product has been translated into

- Klingon (thanks, K'Plai)
Implements the pCloud API found at https://docs.pcloud.com/


Installation
------------

Install collective.foo by adding it to your buildout::

[buildout]

...

eggs =
collective.foo


and then running ``bin/buildout``

XXX

Contribute
----------

- Issue Tracker: https://github.com/collective/collective.foo/issues
- Source Code: https://github.com/collective/collective.foo
- Documentation: https://docs.plone.org/foo/bar


Support
-------

If you are having issues, please let us know.
We have a mailing list located at: [email protected]
- Issue Tracker: https://github.com/tomgross/pycloud/issues
- Source Code: https://github.com/tomgross/pycloud


License
Expand Down
1 change: 1 addition & 0 deletions src/pycloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#
from pycloud.main import PyCloud
33 changes: 24 additions & 9 deletions src/pycloud/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,56 @@
import requests
from hashlib import sha1


def main():
parser = argparse.ArgumentParser(description='pCloud command line client')
parser.add_argument('username',
help='The username for login into your pCloud account')
parser.add_argument('password',
help='The password for login into your pCloud account')
args = parser.parse_args()
pyc = PyCloud()
print(pyc.get_auth_token(args.username, args.password))
pyc = PyCloud(args.username, args.password)


class PyCloud(object):

endpoint = 'https://api.pcloud.com/'

def __init__(self, username, password):
self.username = username.lower().encode('utf-8')
self.password = password.encode('utf-8')
self.auth_token = self.get_auth_token()

# Authentication
def getdigest(self):
resp = requests.get(self.endpoint + 'getdigest')
return resp.json()['digest']
return bytes(resp.json()['digest'], 'utf-8')

def get_auth_token(self, username, password):
def get_auth_token(self):
digest = self.getdigest()
l_username = bytes(username.lower(), 'utf-8')
passworddigest = sha1(
bytes(password, 'utf-8') +
bytes(sha1(l_username).hexdigest(), 'utf-8') +
bytes(digest, 'utf-8'))
self.password +
bytes(sha1(self.username).hexdigest(), 'utf-8') +
digest)
resp = requests.get(self.endpoint + 'userinfo',
params={'getauth': 1,
'logout': 1,
'username': username,
'username': self.username,
'digest': digest,
'passworddigest': passworddigest.hexdigest()}
)
return resp.json()['auth']

# Folders
def listfolder(self, path=None, folderid=0):
params = {'auth': self.auth_token}
if path is not None:
params['path'] = path
else:
params['folderid'] = folderid
resp = requests.get(self.endpoint + 'listfolder', params=params)
return resp.json()


if __name__ == '__main__':
main()

0 comments on commit 9ffc53a

Please sign in to comment.