Esempio n. 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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 8
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})
Esempio n. 9
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})
Esempio n. 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='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
Esempio n. 11
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})
Esempio n. 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})
Esempio n. 13
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})
Esempio n. 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='******')

    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='ar')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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='******')

    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})
Esempio n. 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})
Esempio n. 20
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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 24
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})
Esempio n. 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})
Esempio n. 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})
Esempio n. 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))
Esempio n. 28
0
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})
Esempio n. 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})
Esempio n. 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='es')
        post.translatedText = json.dumps(translation,
                                         indent=2,
                                         ensure_ascii=False)
    return render(request, 'blog/post_list.html', {'posts': posts})