Skip to content

Commit

Permalink
Modified change_sis_id_from_error_report report script (unsupported#114)
Browse files Browse the repository at this point in the history
* Removed unused data parameter.

* Removed unused data variable and corrected spelling mistake.

* Added last working date.

* updated README to clarify the value used for login_id

* Refactored and simplified change_sis_id_from_error_report script.
  • Loading branch information
CaseyInHaengsin authored and colincromar committed Aug 30, 2019
1 parent 7178baa commit 3157d54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion api/create_sandbox_courses_without_sisids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This script can be used to create sandbox courses for teachers. This script will
<tr>
<td>first_name</td>
<td>last_name</td>
<td>email</td>
<td>login_id</td>
</tr>
<tr>
<td>John</td>
Expand Down
2 changes: 1 addition & 1 deletion sis/change_sis_id_from_error_report/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LAST WORKING AS OF 07/31/2018
LAST WORKING AS OF 08/30/2019


<h1>Change_sis_id.csv Generator</h1>
Expand Down
61 changes: 33 additions & 28 deletions sis/change_sis_id_from_error_report/fix_sis_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,35 @@
#This value is used to write a new CSV
name_of_fixed_csv = ''
#This is the the sis_id you would like to change. Values accepted are account, term, course, section, group, group_category, user
type = ''
type = 'user'


def main():
total_val = read_csv()
total_val.pop(0)
final_test = []
for item in total_val:
try:
final_test.append(get_info(item))
except:
print('Failed at {}'.format(item))
#Write CSV
with open(name_of_fixed_csv, 'w') as write_csv:
csv_writer = csv.writer(write_csv)
csv_writer.writerow(['old_id', 'new_id', 'type'])
for data in final_test:
with open(name_of_fixed_csv, 'a') as writ:
csv_writ = csv.writer(writ)
csv_writer.writerow([data[0], data[1], data[2]])

##Trying to use this with new, better code
def find_between_r(s, first, last):
try:
start = s.rindex(first) + len(first)
end = s.rindex(last, start)
return s[start:end]
except ValueError:
return ""

#The read_csv function is reading the provisioning report with errors and saving it in an list
def read_csv():
Expand All @@ -22,35 +50,12 @@ def read_csv():
def get_info(whole_string):
while whole_string:
try:
split_string = re.split('\\SIS ID\\b', whole_string)[-1]
split_string = whole_string.split('ID', 1)[1]
temp_id = split_string.split()
curr_id = temp_id[0]
s = whole_string.replace("'s", '')
temp_place_holder = s.split('claimed', 1)[1]
temp_split = temp_place_holder.split()
new_sis_id = temp_split[0]
curr_id = find_between_r(whole_string, 'SIS ID', 'has already')
new_sis_id = find_between_r(whole_string, 'already claimed', 'user_id requested')
val = [curr_id, new_sis_id, type]
return val

except:
print('Error at string {stri}'.format(stri=split_string))

total_val = read_csv()
total_val.pop(0)
final_test = []
for item in total_val:
try:
final_test.append(get_info(item))
except:
print('Failed at {}'.format(item))


#Write CSV
with open(name_of_fixed_csv, 'w') as write_csv:
csv_writer = csv.writer(write_csv)
csv_writer.writerow(['old_id', 'new_id', 'type'])
for data in final_test:
with open(name_of_fixed_csv, 'a') as writ:
csv_writ = csv.writer(writ)
csv_writer.writerow([data[0], data[1], data[2]])
if __name__ == "__main__":
main()

0 comments on commit 3157d54

Please sign in to comment.