def decode(cls, registry: Registry, args): local = registry.get_service(args.local_service, 'local') # TODO: use disambiguate if args.all: raw_resources = registry.find_all_resources(service=args.service, category=cls.name) else: raw_resources = [ registry.find_resource(title=args.title, service=args.service, category=cls.name) ] for raw_resource in raw_resources: try: destination_path = local.find_existing(registry, raw_resource.title) except FileNotFoundError: destination_path = local.make_markdown_filename( raw_resource.title) if args.destination: destination_path = os.path.join(args.destination, destination_path) decoded_markdown, extra_files = cls.decode_json( registry, raw_resource.data, args) local.write(destination_path, decoded_markdown) for path, data in extra_files: local.write(path, data)
def download(cls, registry: Registry, args): if args.all: cls.download_all(registry, args) return canvas = registry.get_service(args.service, "canvas") resource_json = cls.find(canvas, args.title) if resource_json is not None: try: registry.find_resource(canvas.name, cls.name, args.title, "") print("Downloaded new version of {}: ".format(cls.name), args.title) except WaltzException: print("Downloaded new {}:".format(cls.name), args.title) resource_json = json.dumps(resource_json) registry.store_resource(canvas.name, cls.name, args.title, "", resource_json) return resource_json cls.find_similar(registry, canvas, args)
def upload(cls, registry: Registry, args): canvas = registry.get_service(args.service, "canvas") raw_resource = registry.find_resource(title=args.title, service=args.service, category=args.category, disambiguate=args.url) full_page = json.loads(raw_resource.data) canvas.api.put("pages/{url}".format(url=full_page['title']), data={ 'wiki_page[title]': full_page['title'], 'wiki_page[body]': full_page['body'], 'wiki_page[published]': full_page['published'] })
def upload(cls, registry: Registry, args): canvas = registry.get_service(args.service, "canvas") raw_resource = registry.find_resource(title=args.title, service=canvas.name, category=cls.name, disambiguate="") full_assignment = json.loads(raw_resource.data) assignment_data = cls._make_canvas_upload(registry, full_assignment, args) remote_assignment = cls.find(canvas, args.title) if remote_assignment is None: canvas.api.post('assignments/', data=assignment_data) else: canvas.api.put("assignments/{aid}".format(aid=remote_assignment['id']), data=assignment_data)
def upload(cls, registry: Registry, args): blockpy = registry.get_service(args.service, cls.default_service) raw_resource = registry.find_resource(title=args.title, service=args.service, category=args.category, disambiguate=args.url) full_data = json.loads(raw_resource.data) blockpy.api.post("import", json={ 'course_id': full_data['course_id'], 'assignments': [full_data] })
def decode(cls, registry: Registry, args): course = registry.find_resource(title=args.title, service=args.service, category=cls.name) data = json.loads(course.data) original_destination = args.destination for group in data['groups']: custom_args = SimpleNamespace(**vars(args)) custom_args.title = group BlockPyGroup.decode(registry, custom_args) for group, problems in data['problems'].items(): for problem in problems: custom_args = SimpleNamespace(**vars(args)) custom_args.title = problem custom_args.destination = group Problem.decode(registry, custom_args)
def upload(cls, registry: Registry, args): canvas = registry.get_service(args.service, "canvas") # Get the local version raw_resource = registry.find_resource(title=args.title, service=args.service, category=args.category, disambiguate=args.id) local_quiz = json.loads(raw_resource.data) # Get the remote version remote_quiz = cls.find(canvas, args.title) # Either put or post the quiz if remote_quiz is None: cls.upload_new(registry, local_quiz, args) else: cls.upload_edit(registry, remote_quiz, local_quiz, args)