Skip to content

Instantly share code, notes, and snippets.

@dschep dschep/
Last active Feb 17, 2019

What would you like to do?
PushBullet notifications when files change in Dropbox
#!/usr/bin/env python
import time
import shelve
# dropbox uses posix paths and this script should work on windows too
import posixpath
from StringIO import StringIO
from dropbox import client, rest, session
import requests
# dropbox is case insensitive
# tailing / so that foo doesn't match foobar
if not WATCH_DIR.endswith('/'):
WATCH_DIR += '/'
shelf ='secrets')
if 'pushbullet_api_key' not in shelf:
shelf['pushbullet_api_key'] = raw_input('PushBullet API Key: ')
if 'api_key' not in shelf:
shelf['api_key'] = raw_input('Dropbox API Key: ')
if 'api_secret' not in shelf:
shelf['api_secret'] = raw_input('Dropbox API Secret: ')
sess = session.DropboxSession(shelf['api_key'], shelf['api_secret'], 'dropbox')
if 'token_key' not in shelf:
request_token = sess.obtain_request_token()
# Make the user sign in and authorize this token
print "url:", sess.build_authorize_url(request_token)
print "Please visit this website and press the 'Allow' button, then hit",
print "'Enter' here."
# This will fail if the user didn't visit the above URL and hit 'Allow'
access_token = sess.obtain_access_token(request_token)
shelf['token_key'] = access_token.key
shelf['token_secret'] = access_token.secret
sess.set_token(shelf['token_key'], shelf['token_secret'])
device_id = requests.get('',
auth=(shelf['pushbullet_api_key'], ''))\
client = client.DropboxClient(sess)
resp =
while True:
resp =['cursor'])
changes = []
for entry, meta in resp['entries']:
if meta is None or meta['is_dir'] or \
not (posixpath.split(entry)[0] + '/').startswith(WATCH_DIR):
file_ = StringIO(client.get_file(entry).read()) = posixpath.split(entry)[1]'',
auth=(shelf['pushbullet_api_key'], ''),
data=dict(device_id=device_id, type='file'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.