Created
March 15, 2018 15:33
-
-
Save zmousm/0131c3d8b038ee5683933b113a600fc8 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 | |
# -*- coding: utf-8; -*- | |
import sys | |
import csv | |
import urllib | |
import subprocess | |
import os | |
import re | |
from datetime import datetime | |
from contextlib import contextmanager | |
@contextmanager | |
def cd(path): | |
old_dir = os.getcwd() | |
os.chdir(path) | |
yield | |
os.chdir(old_dir) | |
def read_csv(furl, dictreader=True): | |
csv_f = open(furl, 'rb') | |
csv_data = csv_f.read() | |
dialect = csv.Sniffer().sniff(csv_data) | |
if dictreader: | |
reader = csv.DictReader(csv_data.splitlines(), dialect=dialect) | |
else: | |
reader = csv.reader(csv_data.splitlines(), dialect=dialect) | |
return reader | |
organization_id = str(sys.argv[2]) | |
_date_format = "%Y-%m-%d %H:%M:%S" | |
created_at = datetime.utcnow() | |
expire_year = created_at.year | |
if created_at.month > 10: | |
expire_year += 1 | |
expires_at = created_at.replace( | |
year=expire_year, | |
month=10, | |
day=31, | |
hour=23, | |
minute=59, | |
second=59, | |
microsecond=0 | |
) | |
created_at = created_at.strftime(_date_format) | |
updated_at = created_at | |
expires_at = expires_at.strftime(_date_format) | |
out = [] | |
for l in read_csv(sys.argv[1]): | |
outl = [ | |
organization_id, | |
l.get("eduPersonPrincipalName", "NULL"), | |
l.get("UserPrincipalName", "NULL"), | |
l.get("DisplayName", "NULL"), | |
"NULL", # mail | |
"NULL", # password | |
"2", # type | |
"1", # level | |
"5", # status | |
"1", # mfa_status | |
l.get("ImmutableId", "NULL"), | |
l.get("eduPersonAffiliation", "NULL"), | |
"NULL", # remember_token | |
expires_at, | |
created_at, | |
updated_at | |
] | |
out.append(outl) | |
writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL) | |
writer.writerows(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment