Skip to content

Instantly share code, notes, and snippets.

@chrisseto
Created April 13, 2015 15:18
Show Gist options
  • Save chrisseto/4e8ef20dc6465cdfcdb1 to your computer and use it in GitHub Desktop.
Save chrisseto/4e8ef20dc6465cdfcdb1 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "",
"signature": "sha256:5414b12e5613456d6b81de472be9f5d902c5ef090fa39aad4abc1864f95ad48c"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import asyncio\n",
"\n",
"from waterbutler.core import streams\n",
"from waterbutler.providers.s3 import S3Provider\n",
"from waterbutler.providers.box import BoxProvider\n",
"from waterbutler.providers.github import GitHubProvider\n",
"from waterbutler.providers.dropbox import DropboxProvider\n",
"from waterbutler.providers.googledrive import GoogleDriveProvider\n",
"\n",
"loop = asyncio.get_event_loop()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"creds = {\n",
" 's3': {'access_key': '...', 'secret_key': '...'},\n",
" 'dropbox': {'token': '...'},\n",
" 'box': {'token': '...'},\n",
" 'github': {'token': '...'},\n",
" 'googledrive': {'token': '...'},\n",
"}\n",
"settings = {\n",
" 's3': {'bucket': 'imatestbucket'},\n",
" 'dropbox': {'folder': '/Folder_Name'},\n",
" 'box': {'folder': '0'},\n",
" 'github': {'repo': 'TestRepo', 'owner': 'chrisseto'},\n",
" 'googledrive': {'folder': {'id': 'root', 'name': u'Folder Name', 'path': u'Folder%20Name'}},\n",
"}"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"s3 = S3Provider({}, creds['s3'], settings['s3'])\n",
"box = BoxProvider({}, creds['box'], settings['box'])\n",
"github = GitHubProvider({}, creds['github'], settings['github'])\n",
"dropbox = DropboxProvider({}, creds['dropbox'], settings['dropbox'])\n",
"googledrive = GoogleDriveProvider({}, creds['googledrive'], settings['googledrive'])\n",
"\n",
"github.name = 'chrisseto'\n",
"github.email = '[email protected]'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# List the root directory of google drive\n",
"loop.run_until_complete(box.metadata('/'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": [
"[{'provider': 'box',\n",
" 'name': 'folder',\n",
" 'kind': 'folder',\n",
" 'path': '/3281410086/',\n",
" 'extra': {}},\n",
" {'provider': 'box',\n",
" 'name': 'new folder name',\n",
" 'kind': 'folder',\n",
" 'path': '/3281480428/',\n",
" 'extra': {}},\n",
" {'provider': 'box',\n",
" 'name': 'new folder name2',\n",
" 'kind': 'folder',\n",
" 'path': '/3285895474/',\n",
" 'extra': {}},\n",
" {'provider': 'box',\n",
" 'name': 'test',\n",
" 'kind': 'folder',\n",
" 'path': '/3281288758/',\n",
" 'extra': {}},\n",
" {'provider': 'box',\n",
" 'name': 'test folder again1',\n",
" 'kind': 'folder',\n",
" 'path': '/3286724790/',\n",
" 'extra': {}},\n",
" {'provider': 'box',\n",
" 'name': 'Test1',\n",
" 'kind': 'folder',\n",
" 'path': '/3120612255/',\n",
" 'extra': {}},\n",
" {'contentType': None,\n",
" 'extra': {'etag': '0', 'fullPath': None},\n",
" 'size': None,\n",
" 'path': '/26848554703/<p>lol.txt',\n",
" 'modified': None,\n",
" 'provider': 'box',\n",
" 'name': '<p>lol.txt',\n",
" 'kind': 'file'},\n",
" {'contentType': None,\n",
" 'extra': {'etag': '0', 'fullPath': None},\n",
" 'size': None,\n",
" 'path': '/28128613656/bashrc',\n",
" 'modified': None,\n",
" 'provider': 'box',\n",
" 'name': 'bashrc',\n",
" 'kind': 'file'},\n",
" {'contentType': None,\n",
" 'extra': {'etag': '0', 'fullPath': None},\n",
" 'size': None,\n",
" 'path': '/26792383311/bashrc.txt',\n",
" 'modified': None,\n",
" 'provider': 'box',\n",
" 'name': 'bashrc.txt',\n",
" 'kind': 'file'},\n",
" {'contentType': None,\n",
" 'extra': {'etag': '4', 'fullPath': None},\n",
" 'size': None,\n",
" 'path': '/28127855422/foo',\n",
" 'modified': None,\n",
" 'provider': 'box',\n",
" 'name': 'foo',\n",
" 'kind': 'file'},\n",
" {'contentType': None,\n",
" 'extra': {'etag': '1', 'fullPath': None},\n",
" 'size': None,\n",
" 'path': '/28127908846/kodi-14.0-Helix-x86_64.dmg',\n",
" 'modified': None,\n",
" 'provider': 'box',\n",
" 'name': 'kodi-14.0-Helix-x86_64.dmg',\n",
" 'kind': 'file'}]"
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Get information about a single file\n",
"loop.run_until_complete(s3.metadata('/myfile.txt'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
"{'name': 'myfile.txt',\n",
" 'size': '39',\n",
" 'contentType': 'binary/octet-stream',\n",
" 'provider': 's3',\n",
" 'extra': {'md5': 'be6734c825ee2e94df900152f3514f35'},\n",
" 'path': '/myfile.txt',\n",
" 'modified': 'Mon, 13 Apr 2015 14:00:30 GMT',\n",
" 'kind': 'file'}"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Download a file and print it out\n",
"loop.run_until_complete(loop.run_until_complete(s3.download('/myfile.txt')).read())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
"b'This will be the contents of myfile.txt'"
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Upload a file called myfile.txt; returns (metadata, created)\n",
"loop.run_until_complete(dropbox.upload(streams.StringStream('This will be the contents of myfile.txt'), '/myfile.txt'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"[2015-04-13 10:08:40,168][WARNING][aiohttp.client]: Attempt to decode JSON with unexpected mimetype: text/javascript\n"
]
},
{
"output_type": "stream",
"stream": "stderr",
"text": [
"[2015-04-13 10:08:41,186][WARNING][aiohttp.client]: Attempt to decode JSON with unexpected mimetype: text/javascript\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"text": [
"({'name': 'myfile.txt',\n",
" 'size': 39,\n",
" 'contentType': 'text/plain',\n",
" 'provider': 'dropbox',\n",
" 'extra': {'revisionId': 'baf6011568c8'},\n",
" 'path': '/myfile.txt',\n",
" 'modified': 'Mon, 13 Apr 2015 14:07:48 +0000',\n",
" 'kind': 'file'},\n",
" False)"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Copy a file called \"myfile.txt\" from Dropbox to Box and rename it to \"myfile.dropbox.txt\"; returns (metadata, created)\n",
"loop.run_until_complete(dropbox.copy(box, {'path': '/myfile.txt'}, {'path': '/myfile.dropbox.txt'}))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 13,
"text": [
"({'name': 'myfile.dropbox.txt',\n",
" 'size': 39,\n",
" 'contentType': None,\n",
" 'provider': 'box',\n",
" 'extra': {'fullPath': '/myfile.dropbox.txt', 'etag': '1'},\n",
" 'path': '/28705942404/myfile.dropbox.txt',\n",
" 'modified': '2015-04-13T07:09:40-07:00',\n",
" 'kind': 'file'},\n",
" False)"
]
}
],
"prompt_number": 13
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment