示例#1
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#2
0
def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)  # converting to string and storing in the data
        j = json.loads(data);
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(
            text=post.text,
            source='en',
            target='es')
        post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#3
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='fr')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#4
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#5
0
def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)  # converting to string and storing in the data
        j = json.loads(data);
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(
            text=post.text,
            source='en',
            target='es')
        post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)

    return render(request, 'blog/post_list.html', {'posts': posts})
示例#6
0
def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)  # converting to string and storing in the data
        j = json.loads(data);
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(
            text=post.text,
            source='en',
            target='es')
        post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#7
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    #print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  #converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        #post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        #print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#8
0
文件: views.py 项目: leirhyh/dgb5
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#9
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  #converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        #print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#10
0
def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)  # converting to string and storing in the data
        j = json.loads(data);
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(
            text=post.text,
            source='en',
            target='ar')
        post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#11
0
def post_detail(request, pk):
    post = get_object_or_404(Post, pk=pk)
    # Post.objects.get(pk=pk)
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19')

    language_translator = LanguageTranslator(
        username='******',
        password='******')
    data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)  # converting to string and storing in the data
    j = json.loads(data);
    post.info = j['document_tone']['tone_categories'][0]['tones']
    # post.info = json.dumps(post.info);
    post.angerScore = post.info[0]['score']
    post.disgustScore = post.info[1]['score']
    post.fearScore = post.info[2]['score']
    post.joyScore = post.info[3]['score']
    post.sadScore = post.info[4]['score']
    # print(post.info[0]['tone_name'])
    translation = language_translator.translate(
        text=post.text,
        source='en',
        target='ar')
    post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)
    return render(request, 'blog/post_detail.html', {'post': post})
示例#12
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    #print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  #converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        #post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        #print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#13
0
def index(request):
    allinfo = {}
    form = None
    if request.POST:
        form = Form_language(request.POST)
        if form.is_valid():
            data = form.cleaned_data['txtdata']
            logger.info("Text to be process is %s" % data)
            lang = "TBD"

            try:
                language_translation = LanguageTranslation(
                    username=
                    '******',
                    password='******')
                langsdetected = language_translation.identify(data)
                primarylang = langsdetected["languages"][0]['language']
                confidence = langsdetected["languages"][0]['confidence']

                lang = "I am %s confident that the language is %s" % (
                    confidence, primarylang)
            except WatsonException as err:
                allinfo['error'] = err

            allinfo['lang'] = lang
        else:
            allinfo['error'] = "The form is invalid"
    else:
        form = Form_language

    allinfo['form'] = form
    return render(request, 'watson/wlindex.html', allinfo)
示例#14
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#15
0
def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)  # converting to string and storing in the data
        j = json.loads(data);
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(
            text=post.text,
            source='en',
            target='es')
        post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#16
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    #print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  #converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        #post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        #print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#17
0
def post_list(request):
   posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
   tone_analyzer = ToneAnalyzerV3(
   username='******',
   password='******',
   version='2016-05-19 ')
  
   language_translator = LanguageTranslator(
   username='******',
   password='******')


   #print(json.dumps(translation, indent=2, ensure_ascii=False))
 
   for post in posts:
       data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)#converting to string and storing in the data
       j = json.loads(data);
       post.info = j['document_tone']['tone_categories'][0]['tones']
       #post.info = json.dumps(post.info);
       post.angerScore = post.info[0]['score']
       post.disgustScore = post.info[1]['score']
       post.fearScore = post.info[2]['score']
       post.joyScore = post.info[3]['score']
       post.sadScore = post.info[4]['score']
       #print(post.info[0]['tone_name'])
       translation = language_translator.translate(
       text=post.text,
       source='en',
       target='es')
       post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)
   return render(request, 'blog/post_list.html', {'posts': posts})
示例#18
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    #print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  #converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        #post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        #print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#19
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    for post in posts:
        data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
    translation = language_translator.translate(text=post.text,
                                                source='en',
                                                target='es')
    post.translatedText = json.dumps(translation, indent=2, ensure_ascii=False)
    return render(request, 'blog1/post_list.html', {'posts': posts})
示例#20
0
def wlhome():
    # This is how you do logging, in this case information messages.
    app.logger.info('wlhome page requested')
    allinfo = {}
    lang = "TBD"
    txt = None
    form = LangForm()
    # If the form passes this check, then its a POST and the fields are valid. ie. if the
    # request is a GET then this check fails.
    if form.validate_on_submit():
        lang = "TBC"
        txt = form.txtdata.data
        form.txtdata.data = ''

        try:
            language_translation = LanguageTranslation(username='******',
                                                   password='******')
            langsdetected = language_translation.identify(txt)
            primarylang = langsdetected["languages"][0]['language']
            confidence = langsdetected["languages"][0]['confidence']

            lang = "I am %s confident that the language is %s" % (confidence, primarylang)
            session['langtext'] = lang

            allinfo['lang'] = lang
            allinfo['form'] = form
            return redirect(url_for('wlhome'))
        except WatsonException as err:
          allinfo['error'] = err

    allinfo['lang'] = session.get('langtext')
    allinfo['form'] = form
    return render_template('watson/wlindex.html', info=allinfo)
示例#21
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#22
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#23
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    #print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  #converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        #post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        #print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
def wlhome():
    # This is how you do logging, in this case information messages.
    app.logger.info('wlhome page requested')
    allinfo = {}
    lang = 'TBD'
    txt = None
    form = LangForm()
    # If the form passes this check, then its a POST and the fields are valid.
    # ie. if the request is a GET then this check fails.
    if form.validate_on_submit():
        lang = 'TBC'
        txt = form.txtdata.data
        form.txtdata.data = ''
        try:
            language_translation = \
                LanguageTranslation(username=username,
                                    password=password)
            langsdetected = language_translation.identify(txt)
            primarylang = langsdetected["languages"][0]

            lang = \
                "I am {confidence} confident that the language is {language}."
            lang = lang.format(**primarylang)
            session['langtext'] = lang

            allinfo['lang'] = lang
            allinfo['form'] = form
            return redirect(url_for('wlhome'))
        except WatsonException as err:
            allinfo['error'] = err

    allinfo['lang'] = session.get('langtext')
    allinfo['form'] = form
    return render_template('watson/wlindex.html', info=allinfo)
示例#25
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#26
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19')

    language_translator = LanguageTranslator(
        username='******',
        password='******',
    )

    #print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(tone_analyzer.tone(text=post.text), indent=1)
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        #post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        #print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#27
0
def handle_message(event):
    language_translator = LanguageTranslator(username=LT_NAME,
                                             password=LT_PASS)

    language = language_translator.identify(event.message.text)
    reply_json = json.loads(json.dumps(language, indent=2))

    if reply_json['languages'][0]['language'] == "en":
        src = "en"
        tgt = "ja"
        language_code = "0"
    elif reply_json['languages'][0]['language'] == "ja":
        src = "ja"
        tgt = "en"
        language_code = "0"
    else:
        language_code = "1"

    if language_code == "0":
        translation = language_translator.translate(text=event.message.text,
                                                    source=src,
                                                    target=tgt)
        reply = json.dumps(translation, indent=2,
                           ensure_ascii=False).replace("\"", "")
    elif language_code == "1":
        reply = "日本語か英語を入力してね。文章で入力すると理解しやすいよ!"

    line_bot_api.reply_message(event.reply_token, TextSendMessage(text=reply))
示例#28
0
文件: views.py 项目: abrarh93/Myblog
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')[::-1]
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'firstblog/post_list.html', {'posts': posts})
示例#29
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
示例#30
0
def post_list(request):
    posts = Post.objects.filter(
        published_date__lte=timezone.now()).order_by('published_date')
    tone_analyzer = ToneAnalyzerV3(
        username='******',
        password='******',
        version='2016-05-19 ')

    language_translator = LanguageTranslator(
        username='******',
        password='******')

    # print(json.dumps(translation, indent=2, ensure_ascii=False))

    for post in posts:
        data = json.dumps(
            tone_analyzer.tone(text=post.text),
            indent=1)  # converting to string and storing in the data
        j = json.loads(data)
        post.info = j['document_tone']['tone_categories'][0]['tones']
        # post.info = json.dumps(post.info);
        post.angerScore = post.info[0]['score']
        post.disgustScore = post.info[1]['score']
        post.fearScore = post.info[2]['score']
        post.joyScore = post.info[3]['score']
        post.sadScore = post.info[4]['score']
        # print(post.info[0]['tone_name'])
        translation = language_translator.translate(text=post.text,
                                                    source='en',
                                                    target='ja')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})