Skip to content

Instantly share code, notes, and snippets.

@classmember
Last active July 5, 2019 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save classmember/691d74c7cae2554e709177cd03a34bf7 to your computer and use it in GitHub Desktop.
Save classmember/691d74c7cae2554e709177cd03a34bf7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
'''
imports user from csv in format:
<email address>, <first name>, <last name>
'''
import csv
from subprocess import call as run
FILE='example.csv'
def output_csv():
''':returns: list of lines without newline character from file'''
return [_.replace('\n','') for _ in open(FILE, newline='')]
def wp_command(email, first, last):
''':returns: wp cli command in format for subprocess.call parameters'''
return f"wp user create \"{first}\" {email} --role=subscriber --first_name=\"{first}\" --last_name=\"{last}".split(' ')
def main():
'''driver code to import users from csv'''
for row in output_csv():
run(wp_command(*row.split(',')))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment