Skip to content

Commit

Permalink
added read aloud
Browse files Browse the repository at this point in the history
  • Loading branch information
rashiranjan22 committed Jun 7, 2024
1 parent 5209a45 commit 5d67b73
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions newsaggregator/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .views import submit_contact
# from .views import base_view
from .views import news_list
from django.urls import path
from .views import fetch_article_content

app_name='core'

Expand All @@ -26,5 +28,8 @@

path('top-rated/', views.top_rated_articles, name='top_rated_articles'),

# speech
path('fetch_article_content/', fetch_article_content, name='fetch_article_content'),


]
21 changes: 20 additions & 1 deletion newsaggregator/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def scrape(request, name):
from django.shortcuts import render
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from .models import Headline

def news_list(request):
headlines = Headline.objects.all().order_by('-id')
swiper = Headline.objects.all()[:4]
Expand Down Expand Up @@ -205,3 +204,23 @@ def top_rated_articles(request):
top_rated_articles = Headline.objects.filter(average_rating__gte=3.5).order_by('-average_rating')
paginator = Paginator(top_rated_articles, 9)
page = request




import requests
from django.http import JsonResponse

def fetch_article_content(request):
url = request.GET.get('url')
if not url:
return JsonResponse({'error': 'URL parameter is missing'}, status=400)

try:
response = requests.get(url)
response.raise_for_status()
content = response.text
except requests.RequestException as e:
return JsonResponse({'error': str(e)}, status=500)

return JsonResponse({'content': content})
6 changes: 5 additions & 1 deletion newsaggregator/templates/components/news.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
</div>
<button class="submit-btn" onclick="submitRating('{{ record.id }}')">Submit</button>
</div>

<div class="read-aloud-controls">
<button class="btn btn-primary" onclick="startReadAloud('{{ record.url }}', '{{ record.title }}')">Start</button>
<button id="pause-resume-btn" class="btn btn-warning" onclick="pauseReadAloud(this)">Pause</button>
<button class="btn btn-danger" onclick="stopReadAloud()">Stop</button>
</div>


<style>
Expand Down
1 change: 1 addition & 0 deletions newsaggregator/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
}
</script>
<script src="{% static 'assets/js/preloader.js' %}"></script>
<script src="{% static 'assets/js/speech.js' %}"></script>
</body>


Expand Down

0 comments on commit 5d67b73

Please sign in to comment.