def default_validate_session(ses): client = build_client(ses.get('auth_key'), ses.get('auth_secret')) try: ac = client.account_info() return True except: return False
def get(self): # These should always succeed: Site.get can only fail if # there is no logged-in user. if self.site: client = self.site.get_dropbox_client() dropbox_info=None account_good=False if self.site and client: dropbox_info=client.account_info() account_good= (dropbox_info.status == 200) #dropbox_info.data holds the account info, e.g. {u'referral_link': u'https://www.dropbox.com/referrals/NTM1NTU1Mzg5', u'display_name': u'Janus Wesenberg', u'uid': 3555538, u'country': u'SG', u'quota_info': {u'shared': 40610557, u'quota': 5905580032L, u'normal': 3305647577L}, u'email': u'*****@*****.**'} if account_good and ( self.site.dropbox_display_name != dropbox_info.data['display_name'] or self.site.dropbox_email != dropbox_info.data['email'] ): logging.info('Updating dropbox credentials') self.site.dropbox_display_name = dropbox_info.data['display_name'] self.site.dropbox_email = dropbox_info.data['email'] self.site.put() if account_good: logging.debug('/admin: Account good') return self.status(self.site, dropbox_info) logging.debug('/admin: Account not good, showing welcome page') return self.welcome(self.site, dropbox_info)
def auth_test(): session = jafar.get_session() client = build_client(session.get('auth_key'), session.get('auth_secret')) try: str(client.account_info()) return True except Exception, er: return False
def main(): #~ APP_KEY = 'vz2q46h298i5bqy' #~ APP_SECRET = 'f8xid4xf294wrv1' #~ ACCESS_TYPE = 'app_folder' data_serial = "text" width = 1000 height = 700 window_name = "test" number = 100 delay = 5 line_type = cv.CV_AA # change it to 8 to see non-antialiased graphics cpture = cv.CaptureFromCAM(1) cv.SetCaptureProperty(cpture, cv.CV_CAP_PROP_FRAME_WIDTH, 640/2) cv.SetCaptureProperty(cpture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480/2) ulang=1 sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE) request_token = sess.obtain_request_token() url = sess.build_authorize_url(request_token) print "url:", url raw_input() access_token = sess.obtain_access_token(request_token) client = client.DropboxClient(sess) print "linked account:", client.account_info() nomorfile=0 namafile = "initiasinama" aktiv=0 ser.timeout = 5 print "standby" while (ulang==1): image = cv.QueryFrame(cpture) cv.NamedWindow(window_name, 1) cv.ShowImage(window_name, image) data = ser.read(1) if(data=="1"): print("alarm aktiv") aktiv = 1 if (data=="0"): print("password terautentifikasi") aktiv = 0 print("standby") if (aktiv==1): cv.SaveImage("photo.jpg",image) f=open('photo.jpg') namafile="photo"+elinsGetDate()+".jpg" nomorfile=nomorfile+1 response = client.put_file(namafile, f) f.close() print "uploaded: ", namafile
def access_dbx(): authorize_url = flow.start() print authorize_url code = "DTvqi-XTYtYAAAAAAAFwuhgU-Jdp-7kYxhUPhv9T3h8" # This will fail if the user enters an invalid authorization code access_token, user_id = flow.finish(code) client = dropbox.client.DropboxClient(access_token) print "linked account: ", client.account_info() f, metadata = client.get_file_and_metadata("/TEMP/magnum-opus.txt") out = open("magnum-opus.txt", "wb") out.write(f.read()) out.close() print metadata
def is_authorized(session): """Performs a check on authorized based on access_token""" authorized = False if 'dropbox_access_token' in session: try: client = get_client(session['dropbox_access_token']) resp = client.account_info() authorized = True message = 'Authorized.' except rest.ErrorResponse as e: message = str(e) else: message = 'No access token found.' return (authorized,message)
def dropbox_auth_callback(self): # now use the authorized token to grab an access token token = OAuthToken.from_string(self.request.cookies['token']) access_token = dropbox_auth.obtain_access_token(token, "") self.response.headers['Set-Cookie'] = 'token=' # erase the auth token # lookup your account info client = dropbox_client(access_token) account_info = client.account_info().data template_params = { 'access_token':access_token.to_string(), 'email':account_info['email'], } # prompt you to fill in the account credentials for our system path = os.path.join(os.path.dirname(__file__), 'password.html') self.response.out.write(template.render(path, template_params))
def main(): # Include the Dropbox SDK libraries from dropbox import client, rest, session # Get your app key and secret from the Dropbox developer website APP_KEY = 'INSERT_APP_KEY_HERE' APP_SECRET = 'INSERT_SECRET_HERE' # ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app ACCESS_TYPE = 'INSERT_ACCESS_TYPE_HERE' sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE) request_token = sess.obtain_request_token() # Make the user sign in and authorize this token url = sess.build_authorize_url(request_token) print "url:", url print "Please authorize in the browser. After you're done, press enter." raw_input() # This will fail if the user didn't visit the above URL and hit 'Allow' access_token = sess.obtain_access_token(request_token) client = client.DropboxClient(sess) print "linked account:", client.account_info() f = open('working-draft.txt') response = client.put_file('/magnum-opus.txt', f) print "uploaded:", response folder_metadata = client.metadata('/') print "metadata:", folder_metadata f, metadata = client.get_file_and_metadata('/magnum-opus.txt') out = open('magnum-opus.txt', 'w') out.write(f.read()) out.close() print(metadata)
def set_dropdav_password(self): access_token = OAuthToken.from_string(self.request.POST.get('access_token')) password = self.request.POST.get('password') # lookup your account info again to confirm client = dropbox_client(access_token) account_info = client.account_info().data email = account_info['email'] user = DropboxUser.find_by_email(email) if not user: user = DropboxUser(email=email) # create or update your user entry in our system user.access_token = access_token.to_string() user.set_password(password) user.put() # prompt you to fill in the account credentials for our system path = os.path.join(os.path.dirname(__file__), 'success.html') self.response.out.write(template.render(path, {'email':email,'server':site_root()}))
def auth_complete(uid=None, oauth_token=None): session = SESSION_CLASS.load(jafar.get_cookie(SESSION_KEY)) print session, session.data, jafar.get_cookie(SESSION_KEY) assert session.get('auth_key') == oauth_token request_token = dropbox.session.OAuthToken(session.get('auth_key'), session.get('auth_secret')) db_sess = dropbox.session.DropboxSession(DB_APP_KEY, DB_APP_SECRET, DB_APP_TYPE) db_sess.request_token = request_token access_token = db_sess.obtain_access_token(request_token) client = dropbox.client.DropboxClient(db_sess) ac = client.account_info() session.set('auth_key', access_token.key) session.set('auth_secret', access_token.secret) session.set('uid', uid) session.set('valid', True) session.set('username', ac['email']) session.set('fullname', ac['display_name']) session.save() jafar.redirect('/')
import dropbox from dropbox import client, rest, session client = dropbox.client.DropboxClient('CEHAMSGRPBAAAAAAAAAACCi3p6xWFCY5ayssALMM5r7UvoPzdT1_ygQ-LQSH3emB') diccionario= client.account_info() valores = diccionario.values() #espacio total en mb print valores[10]['quota']/1048576 #espacio usado en mb print valores[10]['normal']/1048576
#print "url:", url #print "Please visit this website and press the 'Allow' button, then hit 'Enter' here." #raw_input() # This will fail if the user didn't visit the above URL and hit 'Allow' #access_token = sess.obtain_access_token(request_token) #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
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE) request_token = sess.obtain_request_token() url = sess.build_authorize_url(request_token) w.open(url, new=2) #print "url: ", url print "Visit. Allow. Enter." raw_input() access_token = sess.obtain_access_token(request_token) client = client.DropboxClient(sess) c_a_info = client.account_info() print "Linked: ", c_a_info def get_space(): quota = c_a_info[u'quota_info'][u'quota'] shared = c_a_info[u'quota_info'][u'shared'] normal = c_a_info[u'quota_info'][u'normal'] used = shared + normal return (used, quota) def upload_file(src, dest): with open(src) as f: response = client.put_file(dest, f) print "uploaded: ", response
from watson_developer_cloud import VisualRecognitionV3 as vr #Authorize dropbox connection app_key = raw_input("Enter app key: ") app_secret = raw_input("Enter secret key: ") flow = DropboxOAuth2FlowNoRedirect(app_key, app_secret) authorize_url = flow.start() print '1. Go to: ' + authorize_url print '2. Click "Allow" (you might have to log in first)' print '3. Copy the authorization code.' code = raw_input("Enter the authorization code here: ").strip() 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')
import dropbox from dropbox import client, rest, session client = dropbox.client.DropboxClient( 'CEHAMSGRPBAAAAAAAAAACCi3p6xWFCY5ayssALMM5r7UvoPzdT1_ygQ-LQSH3emB') diccionario = client.account_info() valores = diccionario.values() #espacio total en mb print valores[10]['quota'] / 1048576 #espacio usado en mb print valores[10]['normal'] / 1048576
def store_access_token(): access_token = sess.obtain_access_token(request_token) client = client.DropboxClient(sess) return client.account_info()
print """Could not open the auth URL. Please check your internet connection and restart the app!.""" sys.exit(1) print "Press Enter after you have allowed access" raw_input() # writes the access token to a file for future automation functionality file = open("access_token.dat", "w+") access_token = sess.obtain_access_token(request_token) file.write(str(access_token)) file.close() hookItUp(sess) accntinfo = "linked account:", client.account_info() print accntinfo def sync(myclient=client): mypath = os.path.join(os.path.expanduser("~"), "MyGoogleDocuments") listing = os.listdir(mypath) for infile in listing: try: f = open(os.path.join(mypath, infile)) meta = myclient.search("/", infile) print meta dbresponse = myclient.put_file(infile, f) if DEBUG == True: print "uploaded:", dbresponse except rest.ErrorResponse:
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE) request_token = sess.obtain_request_token() url = sess.build_authorize_url(request_token) w.open(url, new = 2) #print "url: ", url print "Visit. Allow. Enter." raw_input() access_token = sess.obtain_access_token(request_token) client = client.DropboxClient(sess) c_a_info = client.account_info() print "Linked: ", c_a_info def get_space(): quota = c_a_info[u'quota_info'][u'quota'] shared = c_a_info[u'quota_info'][u'shared'] normal = c_a_info[u'quota_info'][u'normal'] used = shared + normal return (used, quota) def upload_file(src, dest): with open(src) as f: response = client.put_file(dest, f) print "uploaded: ", response
access_token_path="/opt/dropbox_token_store.txt" if not j.system.fs.exists(path=access_token_path): authorize_url = flow.start() print '1. Go to: ' + authorize_url print '2. Click "Allow" (you might have to log in first)' print '3. Copy the authorization code.' code = raw_input("Enter the authorization code here: ").strip() access_token, user_id = flow.finish(code) j.system.fs.writeFile(filename=access_token_path,contents=access_token) else: access_token=j.system.fs.fileGetContents(access_token_path) client = dropbox.client.DropboxClient(access_token) print 'linked account: ', client.account_info() months=["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"] import time import ujson import leveldb ago=j.base.time.getEpochAgo("-3m") db=leveldb.DB("/opt/dropbox.db",create_if_missing=True) def download(): has_more=True
def app_create(request): #Dropbox auth client = db_client(request) if not client: return redirect(dropbox_auth) #Make sure tokens are valid try: client.account_info() except: try: del request.session["dropbox_access_token"] del request.session["dropbox_access_token_secret"] return redirect(dropbox_auth) except: return redirect('home') #If form submitted if request.method == 'POST': form = CreateAppForm(request.POST) # A form bound to the POST data if form.is_valid(): # Process the data in form.cleaned_data app_form_vars = {} app_registration_vars = {} app_probe_vars = {} for field_name in form.cleaned_data.keys(): #Registration info if field_name.endswith('REG_INFO'): app_registration_vars[field_name] = form.cleaned_data[field_name] #Configuration update/Upload data info if field_name == 'configUpdate_freq' or field_name == 'dataUpload_freq': if form.cleaned_data[field_name] != None: app_form_vars[field_name] = int(form.cleaned_data[field_name]) #General app info elif not field_name.endswith('Probe') and not field_name.endswith('freq') and not field_name.endswith('duration'): #Clean if app name if field_name == 'app_name': app_form_vars[field_name] = re.sub(r'([^\s\w]|_)+', '', form.cleaned_data[field_name]) else: app_form_vars[field_name] = form.cleaned_data[field_name] #Probe info elif not field_name.endswith('freq') and not field_name.endswith('duration') and not form.cleaned_data[field_name] == False: try: app_probe_vars[field_name] = {} #Extra parameters for UserStudyNotificationProbe if field_name == 'UserStudyNotificationProbe': app_probe_vars[field_name]['URL'] = form.cleaned_data[field_name + '_url'] app_probe_vars[field_name]['TITLE'] = form.cleaned_data[field_name + '_notifyTitle'] app_probe_vars[field_name]['MESSAGE'] = form.cleaned_data[field_name + '_notifyMessage'] app_probe_vars[field_name]['PERIOD'] = int(form.cleaned_data[field_name + '_freq']) app_probe_vars[field_name]['DURATION'] = int(form.cleaned_data[field_name + '_duration']) except: pass #Create json config for app creation config_dict = create_app_config(app_form_vars, app_probe_vars) config_json = json.dumps(config_dict) #Save stats app_creation = Stats(create_time=datetime.datetime.now(), app_name=app_form_vars['app_name'], description=app_form_vars['description'], contact_email=app_form_vars['contact_email'], creator_name=app_registration_vars['creator_name_REG_INFO'], creator_email=app_registration_vars['creator_email_REG_INFO'], org_name=app_registration_vars['org_name_REG_INFO'], location=app_registration_vars['location_REG_INFO'], probe_config=str(config_dict)) app_creation.save() dropbox_account_info = client.account_info() access_token = request.session.get("dropbox_access_token") access_token_secret = request.session.get("dropbox_access_token_secret") AuthHTTP = ComputeEngine.Authorize() ComputeEngine.NewInstance(AuthHTTP, dropbox_account_info["uid"], access_token, access_token_secret, app_form_vars["app_name"], app_form_vars["description"], app_form_vars["contact_email"], config_json) return redirect(app_thanks) # Redirect after POST else: form = CreateAppForm() # An unbound form return render(request, 'app_create.html', {'form': form})
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE) request_token = sess.obtain_request_token() url = sess.build_authorize_url(request_token) print url raw_input() access_token = sess.obtain_access_token(request_token) client = client.DropboxClient(sess) print "linked account:" pprint(client.account_info()) folder_metadata = client.metadata('/') print "metadata:" pprint(folder_metadata) if folder_metadata['is_dir'] == True: print "isdir" else: print "ko" for folder in map(lambda n : n['path'][1:] , client.metadata('/')['contents']): print folder
def account_info(self, request_token, sess): from dropbox import client client = client.DropboxClient(sess) account_info = client.account_info() return account_info
url = sess.build_authorize_url(request_token) #clipboard.Paste(url) print "url:", url print "Please visit this website and press the 'Allow' button, then hit 'Enter' here." raw_input() access_token = sess.obtain_access_token(request_token) print access_token print dir(access_token) print 'Key:' print access_token.key print 'Secret:' print access_token.secret ac_file = open('act.txt', 'w') ac_file.write(str(access_token.key) + '*' + str(access_token.secret)) ac_file.close() client = client.DropboxClient(sess) if args.status: print "Account info:".format(args.filename) print "linked account:", client.account_info() filename = args.filename if filename: print 'uploading file' print filename upload_file = open(filename, 'rb') response = client.put_file(filename, upload_file) print "uploaded:", response
def app_create(request): #Dropbox auth client = db_client(request) if not client: return redirect(dropbox_auth) #Make sure tokens are valid try: client.account_info() except: try: del request.session["dropbox_access_token"] del request.session["dropbox_access_token_secret"] return redirect(dropbox_auth) except: return redirect('home') #If form submitted if request.method == 'POST': form = CreateAppForm(request.POST) # A form bound to the POST data if form.is_valid(): # Process the data in form.cleaned_data app_form_vars = {} app_registration_vars = {} app_probe_vars = {} for field_name in form.cleaned_data.keys(): #Registration info if field_name.endswith('REG_INFO'): app_registration_vars[field_name] = form.cleaned_data[ field_name] #Configuration update/Upload data info if field_name == 'configUpdate_freq' or field_name == 'dataUpload_freq': if form.cleaned_data[field_name] != None: app_form_vars[field_name] = int( form.cleaned_data[field_name]) #General app info elif not field_name.endswith( 'Probe') and not field_name.endswith( 'freq') and not field_name.endswith('duration'): #Clean if app name if field_name == 'app_name': app_form_vars[field_name] = re.sub( r'([^\s\w]|_)+', '', form.cleaned_data[field_name]) else: app_form_vars[field_name] = form.cleaned_data[ field_name] #Probe info elif not field_name.endswith( 'freq') and not field_name.endswith( 'duration' ) and not form.cleaned_data[field_name] == False: try: app_probe_vars[field_name] = {} #Extra parameters for UserStudyNotificationProbe if field_name == 'UserStudyNotificationProbe': app_probe_vars[field_name][ 'URL'] = form.cleaned_data[field_name + '_url'] app_probe_vars[field_name][ 'TITLE'] = form.cleaned_data[field_name + '_notifyTitle'] app_probe_vars[field_name][ 'MESSAGE'] = form.cleaned_data[ field_name + '_notifyMessage'] app_probe_vars[field_name]['PERIOD'] = int( form.cleaned_data[field_name + '_freq']) app_probe_vars[field_name]['DURATION'] = int( form.cleaned_data[field_name + '_duration']) except: pass #Create json config for app creation config_dict = create_app_config(app_form_vars, app_probe_vars) config_json = json.dumps(config_dict) #Save stats app_creation = Stats( create_time=datetime.datetime.now(), app_name=app_form_vars['app_name'], description=app_form_vars['description'], contact_email=app_form_vars['contact_email'], creator_name=app_registration_vars['creator_name_REG_INFO'], creator_email=app_registration_vars['creator_email_REG_INFO'], org_name=app_registration_vars['org_name_REG_INFO'], location=app_registration_vars['location_REG_INFO'], probe_config=str(config_dict)) app_creation.save() dropbox_account_info = client.account_info() access_token = request.session.get("dropbox_access_token") access_token_secret = request.session.get( "dropbox_access_token_secret") AuthHTTP = ComputeEngine.Authorize() ComputeEngine.NewInstance(AuthHTTP, dropbox_account_info["uid"], access_token, access_token_secret, app_form_vars["app_name"], app_form_vars["description"], app_form_vars["contact_email"], config_json) return redirect(app_thanks) # Redirect after POST else: form = CreateAppForm() # An unbound form return render(request, 'app_create.html', {'form': form})