SHARE
TWEET

Untitled

a guest Jul 17th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. '''
  3. imports user from csv in format:
  4. <email address>, <first name>, <last name>
  5. '''
  6. import csv
  7. from subprocess import call as run
  8.  
  9.  
  10. FILE='example.csv'
  11.  
  12. def output_csv():
  13.     ''':returns: list of lines without newline character from file'''
  14.     return [_.replace('\n','') for _ in open(FILE, newline='')]
  15.  
  16. def wp_command(email, first, last):
  17.     ''':returns: wp cli command in format for subprocess.call parameters'''
  18.     return f"wp user create \"{first}\" {email} --role=subscriber --first_name=\"{first}\" --last_name=\"{last}".split(' ')
  19.  
  20. def main():
  21.     '''driver code to import users from csv'''
  22.     for row in output_csv():
  23.         run(wp_command(*row.split(',')))
  24.  
  25. if __name__ == '__main__':
  26.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top