forked from frictionlessdata/frictionless-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dropbox.py
33 lines (29 loc) · 1.03 KB
/
dropbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import dropbox
from pprint import pprint
from tabulator import Stream
from goodtables import Inspector, preset
# 1. Create app to generate access token at https://www.dropbox.com/developers/apps
# 2. And add some csv files to FOLDER on dropbox
ACCESS_TOKEN = '<insert-access-token>'
FOLDER = '/goodtables'
# Get dropbox client
client = dropbox.dropbox.Dropbox(ACCESS_TOKEN)
@preset('dropbox')
def dropbox_preset(source, **options):
warnings = []
tables = []
for item in client.files_list_folder(source).entries:
if item.path_lower.endswith('.csv'):
url = client.files_get_temporary_link(item.path_lower).link
tables.append({
'source': url,
'stream': Stream(url, headers=1, format='csv'),
'schema': None,
'extra': {
'folder': source,
},
})
return warnings, tables
inspector = Inspector(custom_presets=[dropbox_preset])
report = inspector.inspect(FOLDER, preset='dropbox')
pprint(report)