Last active
August 29, 2015 13:56
-
-
Save rickcnagy/9101930 to your computer and use it in GitHub Desktop.
Delete assignments after they've been migrated via upload_gradebook_data.py
This file contains hidden or 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
#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python | |
''' | |
delete assignments after they've been migrated via upload_gradebook_data.py | |
''' | |
import qs | |
import pickle | |
import requests | |
from tqdm import * | |
def main(): | |
# ========= | |
# = Setup = | |
# ========= | |
late_assignments = pickle.load(open(qs.get_filename())) | |
qs.check() | |
posted_assignment_ids = pickle.load(open("posted_{}".format(qs.get_filename()))) | |
success = [] | |
error = [] | |
# ============================= | |
# = Loop through old sections = | |
# ============================= | |
for i in trange(0, len(late_assignments), desc='DEL', leave=True): | |
section_id = late_assignments.keys()[i] | |
# ======================================= | |
# = Loop through assignments in section = | |
# ======================================= | |
for assignment in late_assignments[section_id]: | |
assignment_id = assignment['assignmentId'] | |
if not assignment_id in posted_assignment_ids: | |
continue | |
# if assignment_id in posted_assignment_ids: | |
d = requests.delete("{}sections/{}/assignments/{}".format( | |
qs.get_base_url(), | |
section_id, | |
assignment_id), params=qs.param()) | |
log = qs.ser(d.json(), {'section_id': section_id, | |
'assignment': assignment}) | |
if d.json()['success']: | |
success.append(log) | |
else: | |
error.append(log) | |
qs.wait() | |
print("deleted {} assignments in {} sections".format( | |
len(success), len(late_assignments.keys()))) | |
qs.dump_logs(success, error) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment