Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/bounswe/bounswe2024group2 in…
Browse files Browse the repository at this point in the history
…to dev
  • Loading branch information
hikasap committed Nov 25, 2024
2 parents 34ac061 + c11d6d5 commit 44eb864
Show file tree
Hide file tree
Showing 35 changed files with 5,088 additions and 1,478 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Hello!
This is the repository for the CMPE451 - Group 2 project. We have moved the cmpe352 files to [archive](https://github.com/bounswe/bounswe2024group2/tree/archive-352) branch.
This is the repository for the CMPE451 - Group 2 project. We have moved the cmpe352 files to [archive](https://github.com/bounswe/bounswe2024group2/tree/archive-352) branch.
38 changes: 32 additions & 6 deletions backend/news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework import generics, status
from rest_framework.response import Response
from .serializers import NewsSerializer
from bs4 import BeautifulSoup

class NewsView(generics.CreateAPIView):
serializer_class = NewsSerializer
Expand All @@ -28,12 +29,37 @@ def post(self, request):

response = []
for entry in feed.entries:
response_entry = {
"title": entry.get("title", "No title available"),
"link": entry.get("link", "#"),
"author": entry.get("author", "Unknown"),
"published": entry.get("published", "No publish date available")
}
if feed_name == "financial times":

response_entry = {
"title": entry.get("title", "No title available"),
"link": entry.get("link", "#"),
"author": entry.get("author", "Financial Times"),
"published": entry.get("published", "No publish date available"),
"description": entry.get("summary", "No summary available"),
"image": entry.get("media_thumbnail")[0]['url'] if entry.get("media_thumbnail") and len(entry.get("media_thumbnail")) > 0 else ""
}

elif feed_name == "cryptocurrency":

html_content = entry['summary_detail']['value']

soup = BeautifulSoup(html_content, 'html.parser')

paragraphs = soup.find_all('p')
if len(paragraphs) > 1:
summary_text = paragraphs[1].get_text(strip=True)
else:
summary_text = ''
response_entry = {
"title": entry.get("title", "No title available"),
"link": entry.get("link", "#"),
"author": entry.get("author", "Unknown"),
"published": entry.get("published", "No publish date available"),
"description": summary_text,
"image": entry.get("media_content")[0]['url'] if entry.get("media_content") and len(entry.get("media_content")) > 0 else ""
}

response.append(response_entry)

return Response(response, status=status.HTTP_200_OK)
2 changes: 1 addition & 1 deletion backend/onboarding/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def validate(self, attrs):
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ['url', 'username', 'email']
fields = ['id', 'url', 'username', 'email']


class LogoutSerializer(serializers.Serializer):
Expand Down
2 changes: 1 addition & 1 deletion backend/onboarding/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

router = DefaultRouter()
router.register(r'profiles', ProfileViewSet)
router.register(r'users', UserViewSet)
router.register(r'users', UserViewSet, basename='user')

urlpatterns = [
path("token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
Expand Down
13 changes: 12 additions & 1 deletion backend/onboarding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from rest_framework import generics
from rest_framework import status
from onboarding.utils import Util
from rest_framework.decorators import action

class RegisterView(generics.CreateAPIView):
queryset = User.objects.all()
Expand Down Expand Up @@ -95,7 +96,7 @@ class UserViewSet(viewsets.ModelViewSet):
"""
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
permission_classes = (AllowAny,)

def list(self, request):
currencies = self.get_queryset()
Expand Down Expand Up @@ -125,6 +126,16 @@ def destroy(self, request, pk=None):
currency.delete()
return Response(status=status.HTTP_204_NO_CONTENT)

@action(detail=False, methods=['get'], url_path='(?P<username>[^/.]+)')
def get_by_username(self, request, username=None):
try:
user = self.get_queryset().get(username=username)
except User.DoesNotExist:
return Response({'error': 'User not found'}, status=status.HTTP_404_NOT_FOUND)

serializer = self.get_serializer(user)
return Response(serializer.data)


class LogoutView(generics.GenericAPIView):
permission_classes = (permissions.IsAuthenticated,)
Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ drf-spectacular==0.27.2
django-cors-headers==4.5.0
Pillow
feedparser
yfinance
beautifulsoup4
yfinance
Loading

0 comments on commit 44eb864

Please sign in to comment.