Last active
July 5, 2019 17:26
-
-
Save classmember/691d74c7cae2554e709177cd03a34bf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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