Ejemplo n.º 1
0
def print_articles(tree, locale):
    khan_api = kapi.KhanAPI(locale)
    khan_tree = kapi.KhanContentTree(locale, 'topic')
    lessons = []
    table_rows = []

    khan_tree.get_lessons(lessons, tree)

    for lesson in lessons:
        print("Downloading articles from lesson: %s" % lesson['title'])
        table_rows.append('%s\n' % lesson['title'])
        article_ids = get_article_ids_from_lesson(lesson)
        for i in article_ids:
            article = khan_api.download_article(i)
            tp_link = kapi.create_tp_link(article['node_slug'])
            ka_link = 'https://www.khanacademy.org' + article['relative_url']
            trow ="%s;%s;%s\n" % (article['title'], ka_link, tp_link)
            table_rows.append(trow)
    return table_rows
    parser.add_argument('-l',
                        '--lang',
                        dest='lang',
                        required=True,
                        help='LTT locale')
    #   parser.add_argument('-a','--attribute',dest='key', help='Video attribute from Khan API (e.g. translated_youtube_id)')
    return parser.parse_args()


if __name__ == '__main__':

    opts = read_cmd()
    #opts.key = 'translated_title'

    khan_api = kapi.KhanAPI(opts.lang)
    tree_api = kapi.KhanContentTree(opts.lang, 'video')

    topics = []
    topic_title_map = {}
    tree_api.get_topics(topics)
    for topic in topics:
        english_title = topic['title'].strip().lower()
        translated_title = topic['translated_title'].strip().lower()
        topic_title_map[english_title] = translated_title

    with open(opts.input_file, "r") as f:
        for line in f:
            l = line.split("\t")
            titles = {}
            # Skip empty and commented lines
            if len(l) > 0 and l[0] != '#':
Ejemplo n.º 3
0
        '--input-attribute',
        dest='input_key',
        help='Video attribute from Khan API (e.g. translated_youtube_id)')
    parser.add_argument('-p',
                        '--print',
                        dest='list_keys',
                        action='store_true',
                        help='Print available data attributes')
    return parser.parse_args()


if __name__ == '__main__':

    opts = read_cmd()
    #khan_api = kapi.KhanAPI(opts.lang)
    khan_tree = kapi.KhanContentTree(opts.lang, opts.content_type)

    if opts.list_keys:
        example_ytid = 'ph64kEA6D4c'
        video = khan_api.download_video(example_ytid)
        for k in video.keys():
            print(k)
        sys.exit(0)

    if not opts.output_key:
        print("ERROR: You did not provide the output attribute!")
        print("Try -h to get help.")
        sys.exit(1)

    if not opts.input_key:
        print("ERROR: You did not provide the output attribute!")
Ejemplo n.º 4
0
    opts = read_cmd()
    subject_title  = opts.subject
    lst = opts.list

    if opts.content_type not in AVAILABLE_CONTENT_TYPES:
        print("ERROR: invalid content type argument:", opts.content_type)
        print("Possibilities are:", AVAILABLE_CONTENT_TYPES)
        exit(1)

    if opts.content_type == "article":
        tree_type = 'topic'
    else:
        tree_type = opts.content_type

    khan_tree = kapi.KhanContentTree(opts.lang, tree_type)
    tree = khan_tree.get()

    if subject_title == 'root':
        subtree = tree
    else:
        subtree = kapi.find_ka_topic(tree, subject_title)

    # The following is helpful to determine where things are
    if lst:
        if subtree is not None:
            print("Printing dictionary for topic ", subject_title)
            u.print_dict_without_children(subtree)
            #print("=============================")
            print("Listing topic children for %s" % (subject_title))
            u.print_children_titles(subtree)