-
bosco
@ccc This link is for Microsoft OneDrive. My Dropbox space is limited.
The original link is a more permanent and reliable alias to this URL.
https://onedrive.live.com/?authkey=!AC94lHutmY315L4&id=98B88F62EF7BB2B3!125&cid=98B88F62EF7BB2B3
-
bosco
I believe this is a copy of the last XCode Template modified by @coltonboyd. I have only used it to run the simulator with the latest version of XCode. It throws some warnings, but works for testing.
https://1drv.ms/u/s!ArOye-9ij7iY2GkveJR7rZmN9eS-?e=b37KZi -
bosco
@ihf This script appears to work with python 2 or 3. Try changing #!python3 to #python2. It shouldn't be using simplejson, since json is a core python module. I see now that the your error may be a problem with your requests package. LIne 42 which reads result = r.json coverts the result to json. Line 41 contains json.dumps(data), which converts the arguemnts to a string.
@enceladus Thanks for creating the gist.
-
bosco
@enceladus Please go ahead and make a gist. I hope contribute more in the future when I have more time. Thanks!
-
bosco
@ihf I think there may be multiple versions of Dropbox file picker. The one a modified referenced 'r', not 'response' as the object that receives the download file.
Here is my complete download function.
def download_file(path, dest_filename, progress=None): data = {'path':path} headers = {'Authorization': 'Bearer %s' % (TOKEN,),'Dropbox-API-Arg': json.dumps(data)} url = 'https://content.dropboxapi.com/2/files/download' r = requests.post(url, stream=True, headers=headers) dest_path = os.path.join(os.path.expanduser('~/Documents'), dest_filename) i = 1 while os.path.exists(dest_path): base, ext = os.path.splitext(dest_filename) dest_path = os.path.join(os.path.expanduser('~/Documents'), base + '-' + str(i) + ext) i += 1 size = r.headers.get('Content-Length', 0) bytes_written = 0 canceled = False with open(dest_path, 'w') as f: for chunk in r.iter_content(1024*10): f.write(chunk) bytes_written += len(chunk) if size > 0 and callable(progress): p = float(bytes_written) / float(size) should_cancel = progress(p) if should_cancel: canceled = True break if canceled: os.remove(dest_path)
-
bosco
I fixed one bug.
I had to redefine is_dir or else folders were defined as files.@ui.in_background def load_folder(self): infos = list_folder(self.path) items = [] if self.path != '/': items.append({'title': '..', 'image': 'ionicons-arrow-up-c-32', 'up': True}) if not infos: import console console.alert('Error', 'Could not load folder. Please check if you entered the access token correctly.', 'OK', hide_cancel_button=True) self.status_label.hidden = True return for info in infos: path = info.get('path_display') name = os.path.split(path)[1] if name.startswith('.'): continue #is_dir = info.get('is_dir', False) is_dir = True if info.get('.tag') == 'folder' else False item = {'title': name, 'image': 'ionicons-folder-32' if is_dir else 'ionicons-ios7-download-outline-32', 'accessory_type': 'disclosure_indicator' if is_dir else 'none', 'is_dir': is_dir, 'path': info['path_display']} items.append(item) def c(o1, o2): u_cmp = -1 * cmp(o1.get('up', False), o2.get('up', False)) if u_cmp != 0: return u_cmp d_cmp = -1 * cmp(o1.get('is_dir', False), o2.get('is_dir', False)) if d_cmp == 0: return cmp(o1.get('path', '').lower(), o2.get('path', '').lower()) return d_cmp items.sort(cmp=c) self.tableview.data_source.items = items self.status_label.hidden = True self.name = self.path
-
bosco
Ok. Now I see how to include source.
import requests import urllib import os import ui import json def list_folder(folder_path='/'): headers = {'Authorization': 'Bearer %s' % (TOKEN,),'Content-Type': 'application/json' } if folder_path == '/': folder_path = '' data = {'path':folder_path} r = requests.post('https://api.dropboxapi.com/2/files/list_folder', headers=headers, data=json.dumps(data)) result = r.json() return result.get('entries', None) def download_file(path, dest_filename, progress=None): data = {'path':path} headers = {'Authorization': 'Bearer %s' % (TOKEN,),'Dropbox-API-Arg': json.dumps(data)} url = 'https://content.dropboxapi.com/2/files/download' r = requests.post(url, stream=True, headers=headers)
You also need to replace 'path' with 'path_dislpay' in twice in def load_folder.
@ui.in_background def load_folder(self): infos = list_folder(self.path) items = [] if self.path != '/': items.append({'title': '..', 'image': 'ionicons-arrow-up-c-32', 'up': True}) if not infos: import console console.alert('Error', 'Could not load folder. Please check if you entered the access token correctly.', 'OK', hide_cancel_button=True) self.status_label.hidden = True return for info in infos: path = info.get('path_display') name = os.path.split(path)[1] if name.startswith('.'): continue is_dir = info.get('is_dir', False) item = {'title': name, 'image': 'ionicons-folder-32' if is_dir else 'ionicons-ios7-download-outline-32', 'accessory_type': 'disclosure_indicator' if is_dir else 'none', 'is_dir': is_dir, 'path': info['path_display']}
-
bosco
This is my first post. I will try to include source.
import json def list_folder(folder_path='/'): headers = {'Authorization': 'Bearer %s' % (TOKEN,),'Content-Type': 'application/json' } if folder_path == '/': folder_path = '' data = {'path':folder_path} r = requests.post('https://api.dropboxapi.com/2/files/list_folder', headers=headers, data=json.dumps(data)) result = r.json() return result.get('entries', None) def download_file(path, dest_filename, progress=None): data = {'path':path} headers = {'Authorization': 'Bearer %s' % (TOKEN,),'Dropbox-API-Arg': json.dumps(data)} url = 'https://content.dropboxapi.com/2/files/download' r = requests.post(url, stream=True, headers=headers)
You also need to change 'path' to 'path_display' in two places in def load_folder.
I've been using the v2 dropbox for a year, but hadn't tried to update any pythonista code until today. I have only done a few minutes of testing.
for info in infos: path = info.get('path_display') name = os.path.split(path)[1] if name.startswith('.'): continue is_dir = info.get('is_dir', False) item = {'title': name, 'image': 'ionicons-folder-32' if is_dir else 'ionicons-ios7-download-outline-32', 'accessory_type': 'disclosure_indicator' if is_dir else 'none', 'is_dir': is_dir, 'path': info['path_display']} items.append(item)