What I'd like to do is to build a tree from the dropbox API, for a given path, with share links for each path, using the python bindings.
My proposed structure looks something like this:
[
{
'path': '/a',
'is_dir': True,
'contents': [
{
'path': '/a/b',
'is_dir': True,
'contents': [etc]
},
{
'path': '/a/readme.txt',
'is_dir': False,
'share_link': 'http://etc'
}
]
},
etc.
]
I've got something that mostly works using metadata()
but it's hideously slow as it needs to make an API call per directory traversed.
What I'd like to use instead is delta()
, which will get me every file in one request, then build it into a tree, but I'm having problems figuring out exactly how, in particular how to parse the paths into a tree.
Edit: And I've realised there's a call for each share link so I'm going to omit those and just get them when requested.
Here's some code I have to get the data I need so far:
paths = []
for path, metadata in client.delta(path_prefix='/whatever')['entries']:
paths.append({
'path': path,
'is_dir': metadata['is_dir']
})
So I guess I'm having trouble figuring out how to get those paths nested. Pretty sure I need a recursive function here but can't quite figure it out.