def upload_photos(set, photos, key, secret, checkpoint): try: auth = Auth(key, secret) auth.authenticate() except urllib2.HTTPError as e: print e.read() raise set_controller = Photosets(auth) # Work queue to print upload status ui_wq = WorkQueue(print_status, num_workers = 1) upload_and_add(photos[0], set, auth, set_controller, ui_wq, checkpoint) wq = WorkQueue(upload_and_add, num_workers = 16, max_queue_size = 50, set = set, auth = auth, set_controller = set_controller, ui_wq = ui_wq, checkpoint = checkpoint) for photo in photos[1:]: wq.add(photo) wq.done() ui_wq.done()
def upload_photos(set, photos, key, secret, checkpoint): try: auth = Auth(key, secret) auth.authenticate() except urllib2.HTTPError as e: print e.read() raise set_controller = Photosets(auth) # Work queue to print upload status ui_wq = WorkQueue(print_status, num_workers=1) upload_and_add(photos[0], set, auth, set_controller, ui_wq, checkpoint) wq = WorkQueue(upload_and_add, num_workers=16, max_queue_size=50, set=set, auth=auth, set_controller=set_controller, ui_wq=ui_wq, checkpoint=checkpoint) for photo in photos[1:]: wq.add(photo) wq.done() ui_wq.done()
class TestAuth(unittest.TestCase): def setUp(self): self.auth = Auth() def test_authenticate(self): # put user with username jdoe and password password in storage actual_response = self.auth.authenticate("jdoe", "password") expected_response = True self.assertEqual(expected_response, actual_response) def test_authenticate_wrong_password(self): # put user with username jdoe and password password in storage actual_response = self.auth.authenticate("jdoe", "wrong") expected_response = False self.assertEqual(expected_response, actual_response) def test_is_authenticated(self): # put user with username jdoe and password password in storage # set current user to jdoe actual_response = self.auth.is_authenticated() expected_response = True self.assertEqual(expected_response, actual_response) def test_is_authorized_true(self): # put user with username jdoe and password password in storage # set current user to jdoe with auth_string 0xC command_auth_string = 0x08 actual_response = self.auth.is_authorized(command_auth_string) expected_response = True self.assertEqual(expected_response, actual_response) def test_is_authorized_false(self): # put user with username jdoe and password password in storage # set current user to jdoe with auth_string 0x1 command_auth_string = 0x08 actual_response = self.auth.is_authorized(command_auth_string) expected_response = False self.assertEqual(expected_response, actual_response)
def run_tests(key, secret): try: x = Auth(key, secret) x.authenticate() except urllib2.HTTPError as e: print e.read() raise filename = "/Users/riyer/Desktop/Screen Shot 2013-06-28 at 7.36.02 PM.png" f = open(filename, "rb") pic = f.read() u = Uploader("test_pic", pic, x) u.addTitle("test pic") u.setPublic() req = u.getRequest() try: handle = urllib2.urlopen(req) res = handle.read() except urllib2.HTTPError as e: print e.read() raise photo_id = u.getPhotoIdFromResponse(res) p = Photosets(x) r = p.createGetListRequest() res = execute(r, "createGetListRequest") names = p.getPhotosetList(res) r = p.createNewSetRequest("test set", "test desc", '9404583236') res = execute(r, "createNewSetRequest") set_id = p.getPhotosetIdFromResult(res) r = p.createAddPhotoRequest(photo_id, set_id) execute(r, "createAddPhotoRequest") r = p.createPhotosetDeleteRequest(set_id) execute(r, "createPhotosetDeleteRequest") photos = Photos(x) r = photos.createDeletePhotoRequest(photo_id) execute(r, "createDeletePhotoRequest")
def run(self): auth = Auth() self.browser = auth.authenticate() jobs = [ gevent.spawn(self.inject, url) for url in self.get_scrape_urls() ] gevent.wait(jobs)
def upload_to_drive(self, dryRun=True): if dryRun: return "Would upload {} items to drive".format(self.to_go) drive = Auth.authenticate(slack=False) for item in files: self.to_go -= 1 logging.info("{} backfilled to drive. {} left to go".format( item, self.to_go)) # Upload file to folder. f = drive.CreateFile({ 'title': item, 'parents': [{ 'id': self.folder_id }] }) # Make sure to add the path to the file to upload below. f.SetContentFile("{}{}".format(PHOTOS_DIRECTORY, item)) f.Upload() logging.info("done")
exit_with_error("Unable to find group '" + args['as_group'] + "' in " + config_file) username = common.get_user_value(args, config_data, 'os_username') if username is None: exit_with_error(None) api_key = common.get_user_value(args, config_data, 'os_password') if api_key is None: exit_with_error(None) region = common.get_user_value(args, config_data, 'os_region_name') if region is None: exit_with_error(None) session = Auth(username, api_key, region) if session.authenticate() is True: rv = autoscale(as_group, config_data, args) if rv is None: log_file = None if hasattr(logger.root.handlers[0], 'baseFilename'): log_file = logger.root.handlers[0].baseFilename if log_file is None: logger.info('completed successfull') else: logger.info('completed successfully: %s' % log_file) else: exit_with_error(None) else: exit_with_error('Authentication failed')
import hashlib import binascii import evernote.edam.userstore.constants as UserStoreConstants import evernote.edam.type.ttypes as Types from auth import Auth from tag import Tag from notebook import NoteBook from note import Note auth = Auth() tags = Tag() notebooks = NoteBook() notes = Note() #Authenticate the user using the oauth or developer toke client = auth.authenticate() user_store = client.get_user_store() #Check whether the version is up to date with the latest version provided by evernote version_ok = user_store.checkVersion( "Evernote", UserStoreConstants.EDAM_VERSION_MAJOR, UserStoreConstants.EDAM_VERSION_MINOR ) print("Is my Evernote API version up to date? ", str(version_ok)) print("") if not version_ok: exit(1) note_store = client.get_note_store()