Ejemplo n.º 1
0
def _build_tree(node_data, assessment_dict, lang_code):

    channel = ChannelNode(
        source_id="KA ({0})".format(lang_code),
        source_domain="khanacademy.org",
        title="Khan Academy ({0})".format(lang_code),
        description='Khan Academy content for the {0} language.'.format(
            lang_code),
        thumbnail=
        "https://cdn.kastatic.org/images/khan-logo-vertical-transparent.png",
    )

    # recall KA api for exercises dict
    ka_exercises = requests.get(
        'http://www.khanacademy.org/api/v1/exercises').json()
    mapping = {}
    for item in ka_exercises:
        mapping[item['node_slug'].split('/')[-1]] = item

    # adds mastery models and exercise thumbnails
    for idx in range(len(node_data)):
        if node_data[idx].get('kind') == 'Exercise':
            if node_data[idx].get('id') in mapping:
                copy = node_data[idx]
                copy['image_url_256'] = mapping[node_data[idx].get(
                    'id')]['image_url_256']
                copy['suggested_completion_criteria'] = mapping[
                    node_data[idx].get('id')]['suggested_completion_criteria']
                node_data[idx] = copy

    # get correct base url
    if lang_code != 'en':
        base_path = 'https://{}.khanacademy.org'.format(lang_code.lower())
    else:
        base_path = 'https://www.khanacademy.org'

    # if not lite version in page content, add previews to questions
    lite_version = 'format=lite' in requests.get(base_path)

    channel.path = 'khan'
    node_data.pop(0)

    for node in node_data:
        paths = node['path'].split('/')[:-1]
        # recurse tree structure based on paths of node
        parent = _getNode(paths, channel)
        # nodes with no parents are being returned by content pack maker, hence this check
        if parent is None:
            continue
        child_node = create_node(node, assessment_dict, base_path,
                                 lite_version,
                                 lang_code)  # create node based on kinds
        if child_node and child_node not in parent.children:
            child_node.path = paths[-1]
            parent.add_child(child_node)

    return channel
Ejemplo n.º 2
0
def channel(domain_namespace, channel_source_id, channel_data):
    channel = ChannelNode(channel_source_id,
                          domain_namespace,
                          title=channel_data['name'],
                          description=channel_data['description'],
                          language=channel_data['language'])
    return channel
Ejemplo n.º 3
0
def create_channel(*args, **kwargs):
    channel = ChannelNode(
        source_domain=SOURCE_DOMAIN,
        source_id=SOURCE_ID,
        title=CHANNEL_TITLE,
        thumbnail=
        "https://lh3.googleusercontent.com/zwwddqxgFlP14DlucvBV52RUMA-cV3vRvmjf-iWqxuVhYVmB-l8XN9NDirb0687DSw=w300",
    )

    return channel
Ejemplo n.º 4
0
def create_channel(*args, **kwargs):
    global DEBUG_MODE
    DEBUG_MODE = 'debug' in kwargs
    language = kwargs['language']
    validate_language(language)
    channel = ChannelNode(title='Pratham Open School {}'.format(language),
                          source_domain=DOMAIN,
                          source_id='pratham-open-school-{}'.format(language),
                          thumbnail=get_absolute_path('img/logop.png'))
    return channel
 def get_channel(self, **kwargs):
     # Create a channel
     channel = ChannelNode(
         source_domain='storyweaver.org.in',
         source_id='Pratham_Books_StoryWeaver',
         title='Pratham Books\' StoryWeaver',
         description='',
         language='en',
     )
     return channel
 def get_channel(self, **kwargs):
     # Create a channel
     channel = ChannelNode(
         source_domain="storyweaver.org.in",
         source_id="Pratham_Books_StoryWeaver",
         title="Pratham Books' StoryWeaver",
         description="",
         language="en",
         thumbnail="thumbnail.png",
     )
     return channel
Ejemplo n.º 7
0
def get_channel_node_from_json(json_tree):
    """
    Build `ChannelNode` from json data provided in `json_tree`.
    """
    channel = ChannelNode(
        title=json_tree['title'],
        description=json_tree['description'],
        source_domain=json_tree['source_domain'],
        source_id=json_tree['source_id'],
        language=json_tree['language'],
        thumbnail=json_tree.get('thumbnail', None),
    )
    return channel
Ejemplo n.º 8
0
def construct_channel(**kwargs):

	#check path
	root_folder = kwargs['folder_path']
	if not os.path.isdir(root_folder):
		raise FileNotFoundException("Invalid path! Path {0} does not exist".format(root_folder))
	
	if not os.path.exists(os.path.join(root_folder,'channelmetadata.ini')):
		raise FileNotFoundException("Invalid path! Path to configuration file '{0}/channelmetadata.ini' does not exist".format(root_folder))
	
	#check ini file
	channel_config = ini_to_json(os.path.join(root_folder,'channelmetadata.ini'))
	if len(list(channel_config)) < 1:
		raise InvalidConfigFile("Channel configuration file contains no channel sections")
		
	if len(list(channel_config)) > 1:
		raise InvalidConfigFile("Channel configuration file contains multiple channel sections")
	
	#check folder to ensure only 1 "root" directory
	dirs = []
	for file in os.listdir(root_folder):
		if file != '.' and file != '..' and os.path.isdir(os.path.join(root_folder,file)):
			dirs.append(os.path.join(root_folder,file))		
	if len(dirs) < 1:
		raise InvalidRootFolder("Missing root channel folder in {0}".format(root_folder))
	if len(dirs) > 1:
		raise InvalidRootFolder("Multiple root channel folders in {0}".format(root_folder))
	
	channel_sec = list(channel_config)[0]
	channel = ChannelNode(
		source_domain 	= channel_config[channel_sec]["domain"],
		source_id 		= channel_config[channel_sec]["source_id"],
		title 			= channel_config[channel_sec]["title"],
		description 	= channel_config[channel_sec].get("description"),
		thumbnail 		= channel_config[channel_sec].get("thumbnail")
	)
	
	#start recursive channel build
	build_tree(channel,dirs[0])    

	return channel
Ejemplo n.º 9
0
    def get_channel(self, **kwargs):
        LANGUAGE = kwargs.get("lang", "en")
        lang_obj = getlang(LANGUAGE)

        title_id_suffix = LANGUAGE
        source_id_suffix = '-{}'.format(LANGUAGE)

        if LANGUAGE == "en":
            source_id_suffix = ''
        elif LANGUAGE == "ar":
            title_id_suffix = lang_obj.native_name

        channel = ChannelNode(
            source_domain='phet.colorado.edu',
            source_id='phet-html5-simulations{}'.format(source_id_suffix),
            title='PhET Interactive Simulations ({})'.format(title_id_suffix),
            thumbnail=
            'https://phet.colorado.edu/images/phet-social-media-logo.png',
            description=
            'The PhET Interactive Simulations project at the University of Colorado Boulder provides a collection of 140 interactive simulations for teaching and learning science and math for upper middle school and high school students. Most content available supports chemistry and physics learning.',
            language=lang_obj,
        )

        return channel
Ejemplo n.º 10
0
    def get_channel(self, **kwargs):
        LANGUAGE = kwargs.get("lang", "en")
        lang_obj = getlang(LANGUAGE)

        if LANGUAGE == "en":
            source_id_suffix = ''
        else:
            source_id_suffix = '-{}'.format(LANGUAGE)

        description = CHANNEL_DESCRIPTIONS.get(LANGUAGE, None)
        if description is None:
            description = CHANNEL_DESCRIPTIONS['en']

        channel = ChannelNode(
            source_domain='phet.colorado.edu',
            source_id='phet-html5-simulations{}'.format(source_id_suffix),
            title='PhET Interactive Simulations ({})'.format(
                lang_obj.native_name),
            thumbnail='chefdata/phet-logo-TM-partners.png',
            description=description,
            language=lang_obj,
        )

        return channel
Ejemplo n.º 11
0
def invalid_channel(channel_source_id, domain_namespace):
    channel = ChannelNode(channel_source_id,
                          domain_namespace,
                          title='Invalid Channel')
    channel.source_id = None
    return channel
 def get_channel(self, **kwargs):
     """
     Override the base class method to load the same data as in `pre_run`.
     """
     channel_dict = self.get_channel_dict(kwargs)
     return ChannelNode(**channel_dict)
Ejemplo n.º 13
0
def construct_channel(*args, **kwargs):
    """ Start by creating your channel """
    # Let's start by creating your own channel (replace <placeholders> with your own values)
    channel = ChannelNode(
        source_domain="vuzy.com",  # (e.g. "jamiealexandre.com")
        source_id="apprentice",  # (e.g. "my-sushi-chef")
        title="My First Try",  # (e.g. "My Sushi Chef Channel")
    )
    """ Create topics to add to your channel """
    # Here we are creating a topic named 'Example Topic'
    exampletopic = TopicNode(source_id="topic-1", title="Example Topic")
    # TODO: Create your topic here

    # Now we are adding 'Example Topic' to our channel
    channel.add_child(exampletopic)
    # TODO: Add your topic to channel here
    """ You can also add subtopics to topics """
    # Here we are creating a subtopic named 'Example Subtopic'
    examplesubtopic = TopicNode(source_id="topic-1a", title="Example Subtopic")
    # TODO: Create your subtopic here

    # Now we are adding 'Example Subtopic' to our 'Example Topic'
    exampletopic.add_child(examplesubtopic)
    # TODO: Add your subtopic to your topic here
    """ You can also add pdfs, videos, and audio files to your channel """
    # Next, let's create a document file called 'Example PDF'
    examplepdf = DocumentNode(
        title="Example PDF",
        source_id="example-pdf",
        files=[DocumentFile(path="http://www.pdf995.com/samples/pdf.pdf")],
        license=licenses.CC_BY_SA)
    # TODO: Create your pdf file here (use any url to a .pdf file)

    # We are also going to add a video file called 'Example Video'
    examplevideo = VideoNode(
        title="Example Video",
        source_id="example-video",
        files=[
            VideoFile(
                path=
                "https://ia600209.us.archive.org/27/items/RiceChef/Rice Chef.mp4"
            )
        ],
        license=licenses.CC_BY_SA)
    # TODO: Create your video file here (use any url to a .mp4 file)

    # Finally, we are creating an audio file called 'Example Audio'
    exampleaudio = AudioNode(
        title="Example Audio",
        source_id="example-audio",
        files=[
            AudioFile(
                path=
                "https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3"
            )
        ],
        license=licenses.CC_BY_SA)
    # TODO: Create your audio file here (use any url to a .mp3 file)

    # Now that we have our files, let's add them to our channel
    channel.add_child(examplepdf)  # Adding 'Example PDF' to your channel
    exampletopic.add_child(
        examplevideo)  # Adding 'Example Video' to 'Example Topic'
    examplesubtopic.add_child(
        exampleaudio)  # Adding 'Example Audio' to 'Example Subtopic'

    # TODO: Add your pdf file to your channel
    # TODO: Add your video file to your topic
    # TODO: Add your audio file to your subtopic

    return channel