def __init__(self): self.hog = cv2.HOGDescriptor() self.hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) warnings.filterwarnings("ignore") self.conf = json.load(open("conf.json")) self.lastUploaded = datetime.datetime.now() self.timestamp = datetime.datetime.now() self.ts = self.timestamp.strftime("%A %d %B %Y %I:%M:%S%p") self.pts = deque(maxlen=32) (self.dX, self.dY) = (0, 0) self.direction = "" self.counter = 0 self.client = None self.avg = None self.for_show = None self.track_windows = None # initialize the camera and grab a reference to the raw camera capture self.camera = cv2.VideoCapture(0) # check to see if the Dropbox should be used if self.conf["use_dropbox"]: # connect to dropbox and start the session authorization process flow = DropboxOAuth2FlowNoRedirect(self.conf["dropbox_key"], self.conf["dropbox_secret"]) print "[INFO] Authorize this application: {}".format(flow.start()) authCode = raw_input("Enter auth code here: ").strip() # finish the authorization and grab the Dropbox client (accessToken, userID) = flow.finish(authCode) self.client = DropboxClient(accessToken) print "[SUCCESS] dropbox account linked"
def __init__(self, key, secret): #See if I already have a stored access_token try: with open('.dbtoken.json', 'r') as json_data_file: data = json.load(json_data_file) accessToken = data['accessToken'] except: accessToken = None if accessToken is None: # connect to dropbox and start the session authorization process flow = DropboxOAuth2FlowNoRedirect(key, secret) logging.info("Authorize this application: {}".format(flow.start())) authCode = input("Enter auth code here: ").strip() # finish the authorization and grab the Dropbox client (accessToken, userID) = flow.finish(authCode) data = {'accessToken': accessToken} with open('.dbtoken.json', 'w') as outfile: json.dump(data, outfile) self.client = DropboxClient(accessToken) logging.info("dropbox account linked") self.Q = Queue() self.thread = Thread(target=self.pull_from_queue, args=()) self.thread.daemon = True self.thread.start()
def link(self, auth_code): auth_flow = DropboxOAuth2FlowNoRedirect(self.app_key, self.app_secret) url = auth_flow.start() access_token, user_id = auth_flow.finish(auth_code) with open(self.TOKEN_FILE, 'w') as f: f.write('oauth2:' + access_token) self.api_client = DropboxClient(access_token)
def __check_configuration(self): self.token = utils.get_config_section(DropboxService.DESCRIPTION.fget(), constants.AUTH_TOKEN) if self.token != None: ## TODO check if it is sstill valid... user may have unistalled the app return self.__fill_app_keys() access_token = None app_key = utils.get_config_section(DropboxService.DESCRIPTION.fget(), constants.APP_KEY) app_secret = utils.get_config_section(DropboxService.DESCRIPTION.fget(), constants.APP_SECRET) req_flow = DropboxOAuth2FlowNoRedirect(app_key, app_secret) authorize_url = req_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.") auth_code = input("Enter the authorization code here: ").strip() ## TODO function that uses this, should be the one to caugh the exception try: access_token, user_id = req_flow.finish(auth_code) except dbrest.ErrorResponse as e: print('Error: %s' % (e,)) utils.write_config_section(DropboxService.DESCRIPTION.fget(), constants.AUTH_TOKEN, access_token) self.token = access_token if not self.__has_backup_data(): print ("You do not seem to have the backup file/folders configured. Pybackdata won't backup anything " + \ "without that setting.") if not self.__has_backup_folder(): print ("You do not seem to have a target location for the backups. Pybackdata won't backup anything " + \ "without that setting.")
def main(): consumer_key = getattr(config, 'CONSUMER_KEY', '') consumer_secret = getattr(config, 'CONSUMER_SECRET', '') if not (consumer_key and consumer_secret): print('Error! Please provide CONSUMER_KEY and CONSUMER_SECRET in ' 'config.json') return flow = DropboxOAuth2FlowNoRedirect(config.CONSUMER_KEY, config.CONSUMER_SECRET) url = flow.start() print('Follow this link and grant access to ViaWebDAV:') print(url, '\n') code = raw_input('Enter the code: ').strip() accessToken, userId = flow.finish(code) print('Your access token: ', accessToken) print(""" Put this token into section ACCESS_TOKENS of config.json, e.g.: { "CONSUMER_KEY": "...", "CONSUMER_SECRET": "...", "ACCESS_TOKENS": { "": "<access-token>", // map the account to "/" "alex": "<another-access-token>" // map the account to "/alex" } } """)
def home(): global flow dropbox_flow_url = None if "dropbox_token" not in config: flow = DropboxOAuth2FlowNoRedirect(config["dropbox_key"], config["dropbox_secret"]) dropbox_flow_url = str(flow.start()) return render_template("index.html", config=config, dropbox_flow_url=dropbox_flow_url)
def link(self): auth_flow = DropboxOAuth2FlowNoRedirect(self.app_key, self.app_secret) url = auth_flow.start() print '1. Go to:', url print '2. Authorize this app.' print '3. Enter the code below and press ENTER.' auth_code = raw_input().strip() access_token, user_id = auth_flow.finish(auth_code) with open(self.TOKEN_FILE, 'w') as f: f.write('oauth2:' + access_token) self.api_client = DropboxClient(access_token)
def login(app_key, app_secret): auth_flow = DropboxOAuth2FlowNoRedirect(app_key, app_secret) url = auth_flow.start() print '1. Go to:', url print '2. Authorize this app.' print '3. Enter the code below and press ENTER.' auth_code = raw_input().strip() access_token, user_id = auth_flow.finish(auth_code) print 'Your access token is:', access_token client = DropboxClient(access_token) return client
def connect_to_dropbox(config): # connect to dropbox and start the session authorization process app_key = config['dropbox_app_key'] app_secret = config['dropbox_app_secret'] auth_flow = DropboxOAuth2FlowNoRedirect(app_key, app_secret) print ('[INFO] Authorize this application: %s' % (auth_flow.start())) authCode = input('Enter auth code here: ').strip() # finish the authorization and grab the Dropbox client (accessToken, userID) = auth_flow.finish(authCode) dropbox_client = DropboxClient(accessToken) print ('[SUCCESS] dropbox account linked') return drop_client
def authentification(): global client, auth, ok, submit global ph, te, flow, form_label, cloud_window conf = json.load(open('conf.json')) client = None ok.config(state='active') if conf["use_dropbox"]: # connect to dropbox and start the session authorization process flow = DropboxOAuth2FlowNoRedirect(conf["dropbox_key"], conf["dropbox_secret"]) ph.insert(10, format(flow.start())) auth.config(state='disabled')
def authentification(): global client conf = json.load(open('conf.json')) client = None if conf["use_dropbox"]: # connect to dropbox and start the session authorization process flow = DropboxOAuth2FlowNoRedirect(conf["dropbox_key"], conf["dropbox_secret"]) print "[INFO] Authorize this application: {}".format(flow.start()) authCode = raw_input("Enter auth code here: ").strip() # finish the authorization and grab the Dropbox client (accessToken, userID) = flow.finish(authCode) client = DropboxClient(accessToken) print "[SUCCESS] dropbox account linked"
def dropbox_auth_start(self): print('dropbox_auth_start') APP_KEY = request.registry.get('ir.config_parameter').get_param( request.cr, openerp.SUPERUSER_ID, 'epps.dropbox_app_key') APP_SECRET = request.registry.get('ir.config_parameter').get_param( request.cr, openerp.SUPERUSER_ID, 'epps.dropbox_app_secret') print "APP_KEY" print APP_KEY print APP_SECRET auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() return werkzeug.utils.redirect(authorize_url) # flow with callback uri authorize_url = self.get_dropbox_auth_flow().start() return werkzeug.utils.redirect(authorize_url)
def connect_to_dropbox(self): """ Connect to Dropbox, allowing us to use their API. """ auth_flow = DropboxOAuth2FlowNoRedirect("cmru2e8mi7ikbbf", "21417x86w06gpdh") authorize_url = auth_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.") auth_code = input("Enter the authorization code here: ").strip() try: access_token, user_id = auth_flow.finish(auth_code) except dbrest.ErrorResponse as e: print(('Error: %s' % (e, ))) return None self.c = DropboxClient(access_token)
def sync(self, cr, uid, ids): """Called from client side (via javascript) to start syncing of particular folder (ids). If Dropbox token is not given for current user, first we obtain one ny allowing Odoo/Dropbox application to access users Dropbox account. Given token is then copy/pasted in user preferences. After obtaining Dropbox token, we create new cron job that will continue to sync that folder every minute. After that user is added to 'followers' of given folder and 'sync_loop' is invoked to perform actual sync. """ # get current user u = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context={}) TOKEN = u.dropbox_token if TOKEN: print "TOKEN len" print len(TOKEN) if not TOKEN: auth_code = u.dropbox_auth_code print(auth_code) if auth_code: auth_code = auth_code.strip() APP_KEY = self.pool['ir.config_parameter'].get_param( cr, SUPERUSER_ID, 'epps.dropbox_app_key') APP_SECRET = self.pool['ir.config_parameter'].get_param( cr, SUPERUSER_ID, 'epps.dropbox_app_secret') auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() try: access_token, user_id = auth_flow.finish(auth_code) except dbrest.ErrorResponse, e: print('Error: %s' % (e, )) return self.pool['res.users'].write(cr, SUPERUSER_ID, uid, {'dropbox_token': access_token}, context={}) TOKEN = access_token
def connect_dropbox(conf): # If dropbox_key is not set, stop program and give informative print to # user if conf["dropbox_key"] != "APP_KEY" or conf["dropbox_secret"] != "SECRET": # connect to dropbox and start the session authorization process print "[INFO] Start authorizing application from Dropbox..." flow = DropboxOAuth2FlowNoRedirect(conf["dropbox_key"], conf["dropbox_secret"]) print "[INFO] Authorizing application using link below:\n{}\n".format( flow.start()) authCode = raw_input("Enter auth code here: ").strip() # # finish the authorization and grab the Dropbox client (accessToken, userID) = flow.finish(authCode) client = DropboxClient(accessToken) print "[SUCCESS] dropbox account linked" print '[INFO] Linked account: ', client.account_info()["display_name"] return client else: print "[ERROR] Add your dropbox information to conf.json!" return None
def _authorize(self): dbg.info('Request access token from Dropbox') flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = flow.start() # print 'Open auth url:', authorize_url #browser = webdriver.PhantomJS(service_log_path=os.path.join(tempfile.gettempdir(), 'ghostdriver.log')) #browser = webdriver.PhantomJS(service_log_path=os.path.join(tempfile.gettempdir(), 'ghostdriver.log'), service_args=['--ignore-ssl-errors=true', '--ssl-protocol=tlsv1']) # Change to rely on browser print( "We need to authorize access to Dropbox. Please visit the following URL and authorize the access:" ) print(authorize_url) print("") code = raw_input("Input the code you got: ").strip() #code = #raw_input("Enter the authorization code here: ").strip() access_token, user_id = flow.finish(code) with open(self.auth_file, 'w') as file: file.write(access_token + "\n") file.write(user_id + "\n") dbg.info('Authentication successful') return (access_token, user_id)
def start_auth_flow(config): """ Create the OAuth2 flow. This allows the user to get auth_token """ __log__.info("Auth code not provided or in config!") auth_flow = DropboxOAuth2FlowNoRedirect(config.get("app_key"), config.get("app_secret")) auth_url = auth_flow.start() auth_code = ask_for_auth_code(auth_url) try: auth_token, user_id = auth_flow.finish(auth_code) except dbrest.ErrorResponse as err: if (err.status == 400): __log__.warn("Got a 400!") # Get auth code and try again. auth_code = ask_for_auth_code(auth_url) return start_auth_flow(config) else: __log__.exception("Falied to finish auth! {}".format(err.body)) return (None, config) # Put the information on a copy of config object configClone = config.copy() configClone.update({ "auth_code": auth_code, "auth_flow": auth_flow, "user_id": user_id, }) return (auth_token, configClone)
def start_auth_flow(config): """ Create the OAuth2 flow. This allows the user to get auth_token """ __log__.info("Auth code not provided or in config! {}".format(config)) auth_flow = DropboxOAuth2FlowNoRedirect( config.get("app_key"), config.get("app_secret") ) # Get the auth stuff. auth_url = auth_flow.start() auth_code = ask_for_auth_code_or_exit(auth_url, config) auth_token, config = try_finish_auth_flow(auth_code, auth_url, config) # Put the information on a copy of config object configClone = config.copy() configClone.update({ "auth_flow": auth_flow, "auth_url": auth_url, }) return (auth_token, configClone)
ap.add_argument("-c", "--conf", required=True, help="path to the JSON configuration file") args = vars(ap.parse_args()) # filter warnings, load the configuration and initialize the Dropbox # client warnings.filterwarnings("ignore") conf = json.load(open(args["conf"])) client = None # check to see if the Dropbox should be used if conf["use_dropbox"]: # connect to dropbox and start the session authorization process flow = DropboxOAuth2FlowNoRedirect(conf["dropbox_key"], conf["dropbox_secret"]) print("[INFO] Authorize this application: {}".format(flow.start())) authCode = input("Enter auth code here: ").strip() # finish the authorization and grab the Dropbox client (accessToken, userID) = flow.finish(authCode) client = DropboxClient(accessToken) print("[SUCCESS] dropbox account linked") # initialize the camera and grab a reference to the raw camera capture #camera = PiCamera() #camera.rotation = conf["rotation"] #camera.resolution = tuple(conf["resolution"]) #camera.framerate = conf["fps"] #rawCapture = PiRGBArray(camera, size=tuple(conf["resolution"])) vs = PiVideoStream((320, 240), 30, conf["rotation"]).start()
AP.add_argument("-c", "--conf", required=True, help="path to the JSON configuration file") ARGS = vars(AP.parse_args()) # filter warnings, load the configuration and initialize the Dropbox # client warnings.filterwarnings("ignore") CONF = json.load(open(ARGS["conf"])) CLIENT = None # check to see if the Dropbox should be used if CONF["use_dropbox"]: # connect to dropbox and start the session authorization process FLOW = DropboxOAuth2FlowNoRedirect(CONF["dropbox_key"], CONF["dropbox_secret"]) print "[INFO] Authorize this application: {}".format(FLOW.start()) AUTH_CODE = raw_input("Enter auth code here: ").strip() # finish the authorization and grab the Dropbox client (ACCESS_TOKEN, USER_ID) = FLOW.finish(AUTH_CODE) CLIENT = DropboxClient(ACCESS_TOKEN) print "[SUCCESS] dropbox account linked" # initialize the camera and grab a reference to the raw camera capture CAMERA = PiCamera() CAMERA.resolution = tuple(CONF["resolution"]) CAMERA.framerate = CONF["fps"] RAW_CAPTURE = PiRGBArray(CAMERA, size=tuple(CONF["resolution"]))
def _get_dropbox_flow(self): return DropboxOAuth2FlowNoRedirect(local.Dropbox_APPKEY, local.Dropbox_APPSECRET)
from dropbox.client import DropboxOAuth2FlowNoRedirect, DropboxClient from dropbox import rest as dbrest auth_flow = DropboxOAuth2FlowNoRedirect('pos53ybtbvmf2dc', 'akmlyilnzwmti9b') authorize_url = auth_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." auth_code = raw_input("Enter the authorization code here: ").strip() try: access_token, user_id = auth_flow.finish(auth_code) except dbrest.ErrorResponse, e: print('Error: %s' % (e, )) # return client = DropboxClient(access_token) print 'linked account: ', client.account_info() f, metadata = client.get_file_and_metadata('/Work/Othodi/data/cities.txt') # f, metadata = client.get_file_and_metadata('/magnum-opus.txt') out_fname = 'cities_from_dropbox.txt' out = open('cities_from_dropbox.txt', 'wb') out.write(f.read()) out.close() print metadata with open(out_fname, 'r'): for line in f: print(line)
def get_authorize_url(self): auth_flow = DropboxOAuth2FlowNoRedirect(self.app_key, self.app_secret) url = auth_flow.start() return url
# construct the argument parser and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-c", "--conf", required=True, help="path to the JSON configuration file") args = vars(ap.parse_args()) # filter warnings, load the configuration and initialize the Dropbox # client warnings.filterwarnings("ignore") conf = json.load(open(args["conf"])) client = None if conf["use_dropbox"]: # connect to dropbox and start the session authorization process flow = DropboxOAuth2FlowNoRedirect(conf["dropbox_key"], os.environ[conf["dropbox_secret"]]) print "[INFO] Authorize this application: {}".format(flow.start()) authCode = os.environ["DROPBOX_ACCESSTOKEN"].strip() # finish the authorization and grab the Dropbox client (accessToken, userID) = flow.finish(authCode) client = DropboxClient(accessToken) print "[SUCCESS] dropbox account linked" # initialize the camera and grab a reference to the raw camera capture camera = PiCamera() camera.resolution = tuple(conf["resolution"]) camera.framerate = conf["fps"] rawCapture = PiRGBArray(camera, size=tuple(conf["resolution"])) # allow the camera to warmup, then initialize the average frame, last
from dropbox.client import DropboxOAuth2FlowNoRedirect from dropbox import client import dropbox from docx import Document from PIL import Image 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