Пример #1
0
host = ''
csv_file = ''

### ------- OPEN THE CONFIG FILE and INSTANTIATE API -------

f = open('config.yml')
params = yaml.load(f)
f.close()

my_host = params['hosts'][host]['host']
my_secret = params['hosts'][host]['secret']
my_token = params['hosts'][host]['token']

looker = LookerApi(host=my_host, token=my_token, secret=my_secret)


def read_csv(file):
    f = open(file, 'rb')
    reader = csv.reader(f)
    header = reader.next()
    output = [dict(zip(header, map(str, row))) for row in reader]
    return output


data = read_csv(csv_file)

for i in data:
    user_id = i['user_id']
    looker.update_user(user_id, i)
			try:
				email = user_info_body['email'].split('@')[1]
			except:
				email = "nothing.com"
				# raise
			print email
			if email != 'looker.com':

				#### Comment out the next line and uncomment the one after!
				print(user_info_body['email'] + "would be disabled if you uncommented the next line")
				# user_info_body['is_disabled'] = True


			# print(user_info_body.email)
			print(user_info_body)
			looker.update_user(u,user_info_body)
		except:
			print("email or update error")
			raise
			errors += 1

print(" ----------------------------- ")
print(" ---------- Summary ----------")
print(" ----------------------------- ")
print(" Users: "+ len(all_users))
print(" Looker Users: "+ looker_user_count)
print(" ----------------------------- ")
print(" Users Disabled: "+ len(ids_to_disable)
print(" Errors: "+ errors)
print(" No Login Users: " + no_login_count)
print(" ----------------------------- ")