Пример #1
0
def fake_thumbnail_file():
    local_path = os.path.join("tests", "testcontent", "generated",
                              "invalidimage.png")
    if not os.path.exists(local_path):
        with open(local_path, 'wb') as imgfile:
            imgfile.write(b'not_a_valid_PNG')
    return ThumbnailFile(local_path)
Пример #2
0
    def construct_channel(self, **kwargs):
        channel = self.get_channel(**kwargs)
        for name, _id in catnum.items():
            cat_node = TopicNode(source_id=str(_id), title=name)
            channel.add_child(cat_node)
            links = crawl.get_all_links(_id)
            for link in list(links):
                zipfilename, title = localise.zip_from_url(link)
                appzip = HTMLZipFile(zipfilename)
                if os.path.exists(zipfilename + "_2.jpg"):
                    thumb = ThumbnailFile(zipfilename + "_2.jpg")
                else:
                    thumb = None
                zipnode = HTML5AppNode(source_id=link,
                                       title=title,
                                       license=licenses.CC_BY,
                                       copyright_holder=CHANNEL_NAME,
                                       files=[appzip],
                                       author=crawl.author_lookup[link],
                                       thumbnail=thumb)
                zipnode.validate()
                cat_node.add_child(zipnode)

            cat_node.validate()
        print("DONE")
        return channel
Пример #3
0
 def test_add_ThumbnailFile(self, low_res_video, thumbnail_path):
     video_node = self.get_video_node(path=low_res_video.name,
                                      thumbnail=None)
     thumbnail_file = ThumbnailFile(thumbnail_path)
     video_node.add_file(thumbnail_file)
     video_node.validate()
     _ = video_node.process_files()
     self.check_correct_thumbnail(video_node)
Пример #4
0
def thumbnail_file():
    local_path = os.path.join("tests", "testcontent", "samples",
                              "thumbnail.png")
    assert os.path.exists(local_path)
    return ThumbnailFile(local_path)
    def construct_channel(self, **kwargs):
 
        def add_resources(resources, node, role=LEARNER):
            for title, url in resources:
                pdf_node = DocumentNode(source_id = "pdf_"+url,
                                        title = title,
                                        license = LICENCE,
                                        files = [DocumentFile(path=url)],
                                        role = role
                                       )
                node.add_child(pdf_node)
  
        def get_things(all_things, parent_node, new_node=True):
            for thing in all_things:
                _id = thing.url.strip('/').split('/')[-1] # TODO hash
                if new_node:
                    this_node = TopicNode(source_id = thing.url,
                                           title=thing.title)
                else:
                    this_node = parent_node
                content_node = make_youtube_video(thing.youtube, "Video: {}".format(thing.title), "video__{}".format(thing.url)) # TODO hash
                if content_node is not None:
                    this_node.add_child(content_node)
               
                try:
                    os.mkdir('html')
                except Exception:
                    pass
                fn = "html/{}.zip".format(_id)
                with open(fn, "wb") as f:
                    f.write(thing.app)
                app_zip = HTMLZipFile(fn)
                if thing.title[0] in "AEIOUaeiou":
                    an = "an"
                else:
                    an = "a" 
                app_node = HTML5AppNode(source_id = "app_{}".format(thing.url),
                                        title = "Being {} {}".format(an, thing.title),
                                        license = LICENCE,
                                        files=[app_zip])
            
                this_node.add_child(app_node)
                if new_node:
                    parent_node.add_child(this_node)
 
        video_list = []
        video_set = set()
        channel = self.get_channel(**kwargs)
        
        role_node = TopicNode(source_id="roles", title="Career Clusters")
        life_skill_node = TopicNode(source_id="lifeskills", title="Life Skills")
        lessons_node = TopicNode(source_id = "lessons", title = "Career-Based Empowerment Lessons",
                                 description = "What is your passion? What are you good at? Whether you think you want to be a fashion designer, a filmmaker, an engineer, or something else, these are two questions you might ask yourself when you think about a career. Watch our role models to learn more.")

        resources_node = TopicNode(source_id="resources", title="Student Resources")
        skill_node = TopicNode(source_id="skill", title="Skill-Based Empowerment Lessons")
        major_node = TopicNode(source_id="major", title="College Majors and Requirements")
        advice_node = TopicNode(source_id="advice", title="College Advice")
        educators_node = TopicNode(source_id="edu", title="Educators, Parents and Mentors") 
        channel.add_child(role_node)
        channel.add_child(lessons_node)
        channel.add_child(resources_node)
        channel.add_child(skill_node)
        channel.add_child(major_node)
        channel.add_child(advice_node)
        channel.add_child(educators_node)

        import majors
        for app in majors.apps:
            major_node.add_child(app)

        if DEBUG: return channel 
        import educators
        for app in educators.apps:
            educators_node.add_child(app)
        for title, resources in educators.resources:
            node = TopicNode(source_id="edu"+title, title=title)
            educators_node.add_child(node)
            add_resources(resources, node, COACH)
        # college advice and lifeskills

        import advice
        for id_, title in advice.videos:
            advice_node.add_child(make_youtube_video(id_, title, id_))
        add_resources(advice.resources, advice_node)

        import skills
        for id_, title in skills.videos:
            skill_node.add_child(make_youtube_video(id_, title, id_))
        add_resources(skills.resources, skill_node)

        if DEBUG: return channel 
 
        _lessons, resources = lessons.lesson_index()
        for lesson in _lessons:
            lesson_node = TopicNode(source_id=lesson.title, title=lesson.title, description=lesson.description)
            for video in lesson.video_ids:
                 lesson_video = make_youtube_video(video, lesson.title, video)
                 lesson_node.add_child(lesson_video)
            add_resources(lesson.resources, lesson_node)
            lessons_node.add_child(lesson_node)

        add_resources(lessons.student_resources(), resources_node)
        
        #return channel # TODO
        
        all_life_skills = list(cg_index.all_life_skills())
        get_things(all_life_skills, life_skill_node)
        
        all_jobs = list(cg_index.all_jobs())#
        # each job has a job.title.
        # TODO WRONG get_things(all_jobs, job_node) -- reimplement 


        # role models
        # setup
        top_lookup = {}
        second_lookup = {}
        for top in clusters.top:
            node = TopicNode(source_id = "role_top_"+top,
                             title = top,
                             description = clusters.cluster_meta[top]['desc'],
                             thumbnail = ThumbnailFile(urljoin("https://careergirls.org/", clusters.cluster_meta[top]['img'])))
            top_lookup[top] = node
            role_node.add_child(node)
        for top, second in clusters.second:
            node = TopicNode(source_id = "role_top_"+top+"_"+second,
                             title = second)
            second_lookup[tuple([top, second])] = node
            top_lookup[top].add_child(node)
            # add "Jobs" tree segment which is relevant
            relevant_jobs = [x for x in all_jobs if x.title == second]
            assert relevant_jobs, "No job for " + repr(second)
            get_things(relevant_jobs, node, new_node=False)
            # dragon ^^^ untested
            
        role_urls = set()
        # populate role_urls with list of all job titles
        for job in all_jobs:
            for role in job.roles:
                role_urls.add(role)

        for role_url in sorted(list(role_urls)):
            _id = role_url.strip('/').split('/')[-1]
            role = cg_index.index_role(role_url)
                          
            role_found= False
            for cluster_role in clusters.role_data:
                if cluster_role[3] in role_url:
                    ## this section was outside the loop before
                    this_role = TopicNode(source_id = "role__{}_{}".format(_id, disambig()),
                                          title="{}, {}".format(role.title, role.name),
                                          description = role.bio)
                    for v_id, v_name in zip(role.video_ids, role.video_names):
                        if v_id is not None:
                            video_node = make_youtube_video(v_id[0], v_name[0], v_id[0])
                            this_role.add_child(video_node)
                            video_list.append(v_id[0])
                            video_set.add(v_id[0])
                    ## end section that was outside the loop before
                    second_lookup[tuple(cluster_role[:2])].add_child(this_role)

                    role_found = True
            assert role_found, role_url
                
            # role_node.add_child(this_role)
        
        print ("DONE")
            
            # todo? : role.skill_links, role.skill_names
                        
            
            
        
            
        
        return channel