Exemple #1
0
def display_selection():
    """Stores and displays embedded video, transcript, and vocabulary of selected talk."""
    
    key_word = request.args.get('key_word')
    title = request.args.get('title')
    slug = request.args.get('slug')
    talk_id = request.args.get('talk_id')
    video= get_video(slug) 
    stored_transcript = Transcript.query.get(talk_id)
    
    #vocab_transcript: a string--used for parsing vocabulary
    #webpage_transcript: a dict --used display text in paragraph format
    if stored_transcript:
        webpage_transcript = get_webpage_transcript(slug)
        vocab_list = Word.query.filter_by(talk_id=talk_id).all()
    else:
        vocab_transcript = get_vocab_transcript(slug) #a string that get's stored
        Transcript.add_transcript(talk_id, slug, vocab_transcript, title)
        webpage_transcript = get_webpage_transcript(slug) # a dict of transcript paragraphs     
    
        vocab_list = []
        for vocab, attributes in get_vocab(vocab_transcript):
        #get_vocab()returns a list of tuple pairs: (vocab, (attributes))
        #need make sure each vocabulary is stored first
            stored_word = Word.query.filter_by(word = vocab, talk_id = talk_id).first()
                    
            if stored_word:
                vocab_list.append(stored_word)
            else:
                vocab = vocab
                stem = attributes[0]
                freq = attributes[1]
                sentence = attributes[2]
                selection = attributes[3]

                word = Word.add_word(word=vocab, 
                                    talk_id=talk_id, 
                                    stem=stem, 
                                    freq=freq, 
                                    sentence=unicode(sentence, 'utf-8'), 
                                    selection=selection)
                                        
                vocab_list.append(word)
    return render_template("display_selection.html",
                            video = video,
                            webpage_transcript = webpage_transcript,
                            vocab_list = vocab_list,
                            key_word = key_word,
                            slug = slug,
                            talk_id = talk_id,
                            title = title)
Exemple #2
0
def fetch_vocab():
    vocab_transcript = request.args.get('vocab_transcript')
    vocab_list = []
    for vocab, attributes in get_vocab(vocab_transcript):
    #get_vocab()returns a list of tuple pairs: (vocab, (attributes))
    #need make sure each vocabulary is stored first
        stored_word = Word.query.filter_by(word = vocab, talk_id = talk_id).first()
                
        if stored_word:
            vocab_list.append(stored_word)
        else:
            vocab = vocab
            stem = attributes[0]
            freq = attributes[1]
            sentence = attributes[2]
            selection = attributes[3]
            word = Word.add_word(word=vocab, 
                                talk_id=talk_id, 
                                stem=stem, 
                                freq=freq, 
                                sentence=unicode(sentence, 'utf-8'), 
                                selection=selection)
            vocab_list.append(word)
    return jsonify({"vocab_list":vocab_list})