def authenticate(): # Get client ID and secret from auth.ini config = get_config() # https://github.com/Imgur/imgurpython/blob/master/examples/auth.ini config.read('auth.ini') # this is the file that holds user credentials client_id = config.get('credentials', 'client_id') client_secret = config.get('credentials', 'client_secret') client = ImgurClient(client_id, client_secret) # Authorization flow, pin example (see docs for other auth types) authorization_url = client.get_auth_url('pin') print (("Go to the following URL: {0}".format(authorization_url))) # Read in the pin, handle Python 2 or 3 here. pin = get_input("Enter pin code: ") # ... redirect user to `authorization_url`, obtain pin (or code or token) ... credentials = client.authorize(pin, 'pin') client.set_user_auth(credentials['access_token'], credentials['refresh_token']) config.set('credentials', 'refresh_token', credentials['refresh_token']) with open('auth.ini', 'w') as configfile: # save config.write(configfile) print ("Authentication successful! Here are the details:") print ((" Access token: {0}".format(credentials['access_token']))) print ((" Refresh token: {0}".format(credentials['refresh_token']))) return client
def post_ldap(DCOS_IP): """ Get the LDAP configuration from the buffer, and post it to a DC/OS cluster available at the DCOS_IP argument. """ config = helpers.get_config(env.CONFIG_FILE) try: #open the LDAP file and load the LDAP configuration from JSON ldap_file = open(env.LDAP_FILE, 'r') helpers.log(log_level='INFO', operation='LOAD', objects=['LDAP'], indx=0, content='** OK **') except IOError as error: helpers.log(log_level='ERROR', operation='LOAD', objects=['LDAP'], indx=0, content=request.text) return False #load entire text file and convert to JSON - dictionary ldap_config = json.loads(ldap_file.read()) ldap_file.close() #build the request api_endpoint = '/acs/api/v1/ldap/config/' url = 'http://' + config['DCOS_IP'] + api_endpoint headers = { 'Content-type': 'application/json', 'Authorization': 'token=' + config['TOKEN'], } data = ldap_config #send the request to PUT the LDAP configuration try: request = requests.put(url, headers=headers, data=json.dumps(data)) request.raise_for_status() #show progress after request helpers.log(log_level='INFO', operation='PUT', objects=['LDAP'], indx=0, content=request.status_code) except requests.exceptions.HTTPError as error: helpers.log(log_level='ERROR', operation='PUT', objects=['LDAP'], indx=0, content=request.status_code) helpers.log(log_level='INFO', operation='PUT', objects=['Users'], indx=0, content=env.MSG_DONE) helpers.get_input(message=env.MSG_PRESS_ENTER) return True
def part1(): input_ = get_input(5)[0] polymer = LinkedList.from_string(input_) #print str(polymer) length = react(polymer) #print str(polymer) return length
def authenticate(): # Get client ID and secret from auth.ini config = get_config() config.read('auth.ini') client_id = config.get('credentials', 'client_id') client_secret = config.get('credentials', 'client_secret') client = ImgurClient(client_id, client_secret) # Authorization flow, pin example (see docs for other auth types) authorization_url = client.get_auth_url('pin') print("Go to the following URL: {0}".format(authorization_url)) # Read in the pin, handle Python 2 or 3 here. pin = get_input("Enter pin code: ") print type(pin) # ... redirect user to `authorization_url`, obtain pin (or code or token) ... credentials = client.authorize(pin, 'pin') client.set_user_auth(credentials['access_token'], credentials['refresh_token']) print("Authentication successful! Here are the details:") print(" Access token: {0}".format(credentials['access_token'])) print(" Refresh token: {0}".format(credentials['refresh_token'])) return client
def authenticate(): """ :rtype: client object """ # result = os.getcwd() src_path = os.path.dirname(os.path.abspath(__file__)) auth_path = "{0}/auth.ini".format(src_path) config = get_config() # config.read('auth.ini') config.read(auth_path) client_id = config.get('credentials','client_id') client_secret = config.get('credentials', 'client_secret') refresh_token = config.get('credentials', 'refresh_token') access_token = config.get('credentials', 'access_token') if not refresh_token: # print 'not refresh token' client = ImgurClient(client_id, client_secret) authorization_url = client.get_auth_url('pin') import webbrowser as wb print("First we need to have your authentication access...") print("Go to browser and open the following URL: {0}".format(authorization_url)) wb.open_new_tab(authorization_url) pin = get_input("Enter the pin code: ") # ... redirect user to `authorization_url`, obtain pin (or code or token) ... credentials = client.authorize(pin, 'pin') # Store the refresh_token new_refresh_token = credentials['refresh_token'] config.set('credentials', 'refresh_token', value=new_refresh_token) refresh_token = new_refresh_token with open(auth_path, 'wb') as configfile: config.write(configfile) if refresh_token and not access_token: client.set_user_auth(access_token, refresh_token) # client = ImgurClient(client_id, client_secret, refresh_token) if not client.auth: print("Auth failed... Please try again") import sys sys.exit() else: print("Auth success! Getting accessing...") client.auth.refresh() new_access_token = client.auth.current_access_token print("New access token generated.") config.set('credentials', 'access_token', value=new_access_token) with open(auth_path, 'wb') as configfile: config.write(configfile) access_token = new_access_token print("Access information saved!") if refresh_token and access_token: # print 'refresh token and access token' client = ImgurClient(client_id, client_secret, access_token, refresh_token) return client
def authenticate(): # Get client ID and secret from auth.ini config = get_config() config.read('auth.ini') client_id = config.get('credentials', 'client_id') client_secret = config.get('credentials', 'client_secret') client = ImgurClient(client_id, client_secret) # Authorization flow, pin example (see docs for other auth types) authorization_url = client.get_auth_url('pin') print("Go to the following URL: {0}".format(authorization_url)) # Read in the pin, handle Python 2 or 3 here. pin = get_input("Enter pin code: ") # ... redirect user to `authorization_url`, obtain pin (or code or token) ... credentials = client.authorize(pin, 'pin') client.set_user_auth(credentials['access_token'], credentials['refresh_token']) print("Authentication successful! Here are the details:") print(" Access token: {0}".format(credentials['access_token'])) print(" Refresh token: {0}".format(credentials['refresh_token'])) return client
def authenticate(): # Get client ID and secret from auth.ini config = get_config() # https://github.com/Imgur/imgurpython/blob/master/examples/auth.ini config.read('auth.ini') # this is the file that holds user credentials client_id = config.get('credentials', 'client_id') client_secret = config.get('credentials', 'client_secret') client = ImgurClient(client_id, client_secret) # Authorization flow, pin example (see docs for other auth types) authorization_url = client.get_auth_url('pin') print(("Go to the following URL: {0}".format(authorization_url))) # Read in the pin, handle Python 2 or 3 here. pin = get_input("Enter pin code: ") # ... redirect user to `authorization_url`, obtain pin (or code or token) ... credentials = client.authorize(pin, 'pin') client.set_user_auth(credentials['access_token'], credentials['refresh_token']) config.set('credentials', 'refresh_token', credentials['refresh_token']) with open('auth.ini', 'w') as configfile: # save config.write(configfile) print("Authentication successful! Here are the details:") print((" Access token: {0}".format(credentials['access_token']))) print((" Refresh token: {0}".format(credentials['refresh_token']))) return client
def main(): inputs = get_input(19) #, 'test') ip = int(inputs[0].split()[-1]) program = [[line[0]] + map(int, line[1:]) for line in map(str.split, inputs[1:])] #print part1(ip, program) print part2(ip, program)
def main(): inputs = get_input(3) claims = load_claims(inputs) board = make_claims(claims) print part1(board) print part2(board, claims)
def part1(): inputs = get_input(24, 'test') groups = parse_input(inputs) winners = run_fights(groups) print winners[0].type print[g.units for g in winners] return sum(g.units for g in winners)
def main(): inputs = get_input(12) #, 'test') initial = inputs[0].split()[-1] #print initial transitions = dict(line.split(' => ') for line in inputs[2:]) #print transitions automata = Automata(initial, transitions) #print part1(automata) print part2(automata)
def part1(): inputs = get_input(15, 'test2') cave = Cave.from_strings(inputs) print str(cave) rounds = run(cave) print str(cave) hp = sum(u.hp for u in cave.units) print rounds, hp return rounds * hp
def part2(): boost = 0 while True: print "boosted", boost inputs = get_input(24) #,'test') groups = parse_input(inputs, boost=boost) winners = run_fights(groups) if all(g.type == Group.IMMUNE for g in winners): return sum(g.units for g in winners) boost += 1
def part1(): inputs = get_input(17) #, 'test') items = [parse_line(l) for l in inputs] offset, dims = get_dimensions(items) #print offset, dims map = Map(offset, dims) map.populate(items) #print str(map) #return demo(map) return run(map)
def load_data(quiet=True): find_path_to_helpers(quiet=quiet) if __package__: from ..helpers import get_input, ints else: from helpers import get_input, ints data = ints(get_input()) return data
def load_posibilities(): inputs = get_input(16, 'part1') possibles = {} for i in xrange(0, len(inputs), 4): before = literal_eval(inputs[i].split(' ', 1)[-1]) op = map(int, inputs[i + 1].split()) after = literal_eval(inputs[i + 2].split(' ', 1)[-1][1:]) possibles.setdefault(op[0], set()).update(possible_ops(before, op, after)) return possibles
def part1(): inputs = get_input(17) #, 'test') for line in inputs: parse_line(line) set_maxy() res = run() #with open('day17.out', 'w') as f: # f.write(stringify()) return res
def load_data(quiet=True): find_path_to_helpers(quiet=quiet) if __package__: from ..helpers import get_input else: from helpers import get_input data = get_input().split("\n\n") return data
def part2(): input_ = get_input(5)[0] units = sorted(set(input_.lower())) lengths = [] for unit in units: inp = input_.replace(unit, '').replace(unit.upper(), '') lengths.append(react(LinkedList.from_string(inp))) return min(lengths)
def get_show(client): """Get information about a television show.""" #show_name = "Adventure Time" show_name = get_input("Enter a show name: ") series = client.get_series(name=show_name) print(ignore_unicode(series.seriesName) + " (%s/10) (%s)" % (ignore_unicode(series.siteRating), ignore_unicode(series.id))) print(ignore_unicode(series.overview)) print(series.banner) """
def main(): inputs = get_input(4) inputs.sort() events = [parse_line(l) for l in inputs] sleeps = list(get_sleeps(events)) elves = correlate(sleeps) id, hour = part1(elves) print id, hour, id * hour id, hour = part2(elves) print id, hour, id * hour
def part1(): inputs = get_input(21) ip = int(inputs[0].split()[-1]) program = [[line[0]] + map(int, line[1:]) for line in map(str.split, inputs[1:])] #assembler = Assembler(6) #x5 = run_once(assembler, ip, program) # sanity check assembler = Assembler(6) assembler.registers[0] = 16457176 run_program(assembler, ip, program)
def main(events_log_file): matomo_url = get_input( "Enter the URL for Matomo (probably https://analytics.tools.signin.service.gov.uk/):" ) console_print("Enter the Matomo API token (this can be found in " "blackbox in 'verify-tools-matomo-api-auth-token.gpg').") matomo_token = getpass(prompt='Token: ') dry_run = '?' while dry_run: dry_run = get_dry_run(dry_run) replay_events(dry_run, matomo_url, matomo_token, events_log_file)
def part2(): possibles = load_posibilities() op_map = {v: k for k, v in deduce_codes(possibles).iteritems()} assembler = Assembler() assembler._opmap = op_map inputs = get_input(16, 'part2') for line in inputs: command = map(int, line.split()) assembler.execute(*command) return assembler.registers[0]
def start_chat(): print('Connected as {}! [type a message or q to quit]'.format(name)) talker = Topic(client, '/messages', 'std_msgs/String') talker.advertise() listener = Topic(client, '/messages', 'std_msgs/String') listener.subscribe(receive_message) while client.is_connected: text = get_input() if text == 'q': break send_message(talker, text) client.terminate()
def part2(): inputs = get_input(15) #, 'test2') power = 3 while True: print power cave = Cave.from_strings(inputs, power) #print str(cave) try: rounds = run_until_death(cave) except DeadElf: power += 1 else: break #print str(cave) print power hp = sum(u.hp for u in cave.units) print rounds, hp return rounds * hp
def authenticate(): config = get_config() config.read('auth.ini') client_id = config.get('credentials', 'client_id') client_secret = config.get('credentials', 'client_secret') client = CloudLink(client_id, client_secret) name = config.get('credentials', 'loginName') pw = config.get('credentials', 'password') # redirect_url = config.get('credentials', 'redirect_url') authorization_url = client.get_auth_url() print("Go to the following URL: " "{0}?name={1}&pw={2}".format(authorization_url, name, pw)) code = get_input("Please enter auth code: ") credentials = client.authorize(code) client.set_user_auth(credentials['access_token'], code) print("Authentication successful! Here are the details:") print(" Access token: {0}".format(credentials['access_token'])) return client
def post_groups_users(DCOS_IP, groups): """ Get the list of groups_users from the load_path provided as an argument, and post it to a DC/OS cluster available at the DCOS_IP argument. """ config = helpers.get_config(env.CONFIG_FILE) try: #open the GROUPS file and load the LIST of groups from JSON groups_users_file = open(env.GROUPS_USERS_FILE, 'r') helpers.log(log_level='INFO', operation='LOAD', objects=['Groups', 'Users'], indx=0, content='** OK **') except IOError as error: helpers.log(log_level='ERROR', operation='LOAD', objects=['Groups', 'Users'], indx=0, content=request.text) helpers.get_input(message=env.MSG_PRESS_ENTER) return False #load entire text file and convert to JSON - dictionary groups_users = json.loads(groups_users_file.read()) groups_users_file.close() for index, group_user in (enumerate(groups_users['array'])): #PUT /groups/{gid}/users/{uid} gid = helpers.escape(group_user['gid']) #array of users for this group_users for index2, user in (enumerate(group_user['users'])): uid = user['user']['uid'] #build the request api_endpoint = '/acs/api/v1/groups/' + gid + '/users/' + uid url = 'http://' + config['DCOS_IP'] + api_endpoint headers = { 'Content-type': 'application/json', 'Authorization': 'token=' + config['TOKEN'], } #send the request to PUT the new USER try: request = requests.put(url, headers=headers) request.raise_for_status() #show progress after request helpers.log(log_level='INFO', operation='PUT', objects=['Groups: ' + gid, 'Users: ' + uid], indx=index2, content=request.status_code) except requests.exceptions.HTTPError as error: helpers.log(log_level='ERROR', operation='PUT', objects=['Groups: ' + gid, 'Users: ' + uid], indx=index2, content=request.text) helpers.log(log_level='INFO', operation='PUT', objects=['Groups', 'Users'], indx=0, content=env.MSG_DONE) helpers.get_input(message=env.MSG_PRESS_ENTER) return True
def test(): input_ = get_input(2, 'test') assert part1(input_) == 12
def part1(): #test() s = get_input(20)[0] return max_length(s)
def authenticate(self): print("Get your access PIN here: %s" % (self.authorization_url,)) pin = get_input("Please enter your PIN: ") self.authorize(pin)
def main(): inputs = get_input(23)#, 'test') bots = [parse_line(l) for l in inputs] #print part1(bots) print part2(bots)
def main(): inputs = get_input(6) points = list(load_points(inputs)) #print part1(points) print part1_alt(points)
def part1(): max_length("^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$") return test() s = get_input(20)[0] return max_length(s)