def upload_and_get_url(file_to_upload, extension): """ Takes a file and extension, uploads file to DBox at random URL with random flename+extension, returns the URL """ import string, random filename = binascii.b2a_hex(os.urandom(30))+extension put = client.put_file(filename, file_to_upload) share = client.share(filename, short_url=False) return {'url':share['url'].replace('https://www.dropbox.com/', 'https://dl.dropboxusercontent.com/'), 'filename':filename}
def share(job): """ Shares the output for a job and returns the link. """ client = get_dropbox_client() try: return client.share( '/Video Automation Platform/jobs/{job}/{job}.mov'.format(job=job)) except ErrorResponse: return False
def dropbox_share(): dropbox_access_token = session.get(DROPBOX_ACCESS_KEY, None) if dropbox_access_token is None: return "please log into dropbox first" filepath = request.args.get('filepath', None) if filepath is None: return "You didn't pass a filepath" dropbox_client = get_client(dropbox_access_token) try: return str(dropbox_client.share(filepath).get('url')) except Exception, e: return e.message
#you do not need any of the above if you run the request_dropbox_token.py application token_file = open('dropbox_token.txt', 'r') token_key,token_secret = token_file.read().split('|') token_file.close() sess = session.DropboxSession(APP_KEY,APP_SECRET, ACCESS_TYPE) sess.set_token(token_key,token_secret) client = client.DropboxClient(sess) print "linked account:", client.account_info() print print "NOW READY TO UPLOAD!!!" print #below you declare what file you are uploading. f = open('working-draft.txt') #below you declare location AND name of file to upload as. Name whatever you desire. response = client.put_file('/fileUploader_linkCreator/magnum-opus.txt', f) print "uploaded:", response print print "FILE UPLOADED SUCCESSFULLY!!" print "...NOW ONTO CREATING LINK" print link = client.share('/fileUploader_linkCreator/magnum-opus.txt') print link
client = dropbox.client.DropboxClient(code) print 'linked account: ', client.account_info() #view folders folder_metadata = client.metadata('/') print 'metadata: ', folder_metadata #download first image file print " " filelocation = raw_input("Enter file location: (example: /Home/13-15-00.jpg) ") f, metadata = client.get_file_and_metadata(filelocation) print metadata im = Image.open(f) im.show() print client.share(filelocation, short_url = False) fileurl = client.share(filelocation, short_url = False) print fileurl.get('url') lasturl = fileurl.get('url') #examine first image file instance = vr(api_key='put your watson ibm api key here', version='2016-05-20') img = instance.classify(images_url = lasturl) a = 0 for things in img['images'][0]['classifiers'][0]['classes']: if((things['score']*100) > a): a = things['score']*100 first = things['class'] print('\n There is a ' + str(things['score']*100) + ' percent chance the image contains: '+ things['class'])
if __name__ == "__main__": uploadFile = "" if len(sys.argv) > 1: uploadFile = sys.argv[1] print "I see you'd like to schlepp", uploadFile else: print "What file to schlepp?: ", uploadFile = raw_input() if (os.path.exists(uploadFile)): print "Good, I found your file." else: print "Looks like I can't find a file called '{0}'.".format(uploadFile) sys.exit(1) SessionInfo = {} if (not(os.path.exists(".schlepp.key"))): print "Didn't find an access token. Getting one for you." getFirstAccessToken() SessionInfo = getPickledAccessToken() print "Schlepping." sess = session.DropboxSession(SessionInfo.key, SessionInfo.secret,dropbox_access_type) sess.set_token(SessionInfo.token,SessionInfo.token_secret) client = client.DropboxClient(sess) f = open(uploadFile) response = client.put_file(uploadFile, f) print "Successfully uploaded. Sharing." shareresponse = client.share(response['path']) print "Shared: ", shareresponse['url']
# Include the Dropbox SDK libraries from dropbox import client, rest, session # Get your app key and secret from the Dropbox developer website APP_KEY = 'vqffib25i3zi8nc' APP_SECRET = 'ae8zppkwbcdql42' # ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app ACCESS_TYPE = 'app_folder' sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE) # We will use the OAuth token we generated already. The set_token API # accepts the oauth_token and oauth_token_secret as inputs. sess.set_token("wdzl5swfk3wk9hqy", "k6c38pyop9zg0en") # Create an instance of the dropbox client for the session. This is # all we need to perform other actions client = client.DropboxClient(sess) # Let's upload a file! import base64 f = open('temp_img').read() img = base64.b64decode(f) response = client.put_file('/test-img.png', img) print "uploaded:", response client.share('/test-img.png', short_url=False) # https://www.dropbox.com/s/s1u52gerceg7bqq/test-img.png --> replace with https://dl.dropboxusercontent.com/s/s1u52gerceg7bqq/test-img.png
files.sort(key=lambda x: os.path.getmtime(x)) for deletefile in files: os.remove(deletefile) return (0) if __name__ == "__main__": storage = cv.CreateMemStorage(0) #cv.NamedWindow('d', 1) #delete the d before inserting into pi color_tracker = ColorTracker() color_tracker.runbrown() #Dropbox Code #dropboxfile=open('filetest.jpg') if (clark == True): dropboxfile=open("/home/pi/image.jpg") response = client.put_file("/image.jpg",dropboxfile) link=client.share(response["path"]) final= link['url'] print final #Twilio Code account = "ACebdd9af86ec48d7d29f805de1c0f75ab" token = "b637248d7e22ad046a388fa122f7022e" client = TwilioRestClient(account, token) message = client.sms.messages.create(to="+18327140243", from_="+18324954516",body="alert, home system detected something. livestream: 192.168.1.6:8081" + final) #play sound mixer.init() alert=mixer.Sound('police_s.wav') alert.play sys.exit() else: sys.exit()