Skip to content

Instantly share code, notes, and snippets.

@MisterDaniels
Last active April 24, 2024 16:52
Show Gist options
  • Save MisterDaniels/e15f924f38159f28e358081f9ad1d225 to your computer and use it in GitHub Desktop.
Save MisterDaniels/e15f924f38159f28e358081f9ad1d225 to your computer and use it in GitHub Desktop.
Verify what image is not in dropbox folder
python verifier.py TOKEN FILE.CSV

Ex:

python verifier.py sl.alldutoken project_images_path.csv
Images not in folder:
File: /class_name/client_name/image_1.jpg
File: /class_name/client_name/image_2.jpg
File: /class_name/client_name/others/image_3.jpg
File: /class_name/client_name/others/image_4.jpg
File: /class_name/client_name/others/image_5.jpg
import csv
import requests
import sys
url = 'https://api.dropboxapi.com/2/files/list_folder'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + sys.argv[1]
}
errors = []
with open(sys.argv[2], newline='') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
if line[0] == 'path':
continue
dropbox_path = line[0]
data = {
"include_deleted": True,
"include_has_explicit_shared_members": False,
"include_media_info": True,
"include_mounted_folders": True,
"include_non_downloadable_files": True,
"path": dropbox_path,
"recursive": False
}
res = requests.post(url, headers=headers, json=data)
json = res.json()
if 'error_summary' not in json:
errors.append({
'path': dropbox_path
})
continue
if 'error_summary' in json:
if 'path/not_folder' not in json['error_summary']:
errors.append({
'path': dropbox_path
})
if errors:
print('Images not in folder:')
for error in errors:
print(f"File: {error['path']}")
else:
print('All images in folder!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment