Skip to content

Commit

Permalink
client
Browse files Browse the repository at this point in the history
  • Loading branch information
tahamusvi committed Mar 22, 2024
1 parent d72a189 commit 5f3fa1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

urlpatterns = [
path('scraper/', ScraperAPIView.as_view(),name="scraper"),
path('clinet/', ClientAPIView.as_view(),name="clinet"),
]
16 changes: 14 additions & 2 deletions server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework.response import Response
from .serializers import *
from rest_framework import status
import requests
#---------------------------
class ScraperAPIView(APIView):
"""Scrape with proxy server"""
Expand All @@ -11,11 +12,22 @@ def post(self, request):
if serializer.is_valid():
scraper = Temsah(serializer.validated_data['url'])
product = scraper.scrape()
print(request.META.get('HTTP_REFERER'))
print(request.META)
url_obj = Urls(applicant_site= request.META.get('HTTP_REFERER'), url= serializer.validated_data['url'])
url_obj.save()

return Response({'message': 'scraper returned.', 'data': product.convert_to_dictionary()})

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
#---------------------------
#---------------------------
class ClientAPIView(APIView):
"""Clinet send request"""
def post(self, request):
url = 'http://localhost:8000/server/scraper/'
data = {"url": request.data.get('url'),}

response = requests.post(url, data=data)

return Response({ 'data': response.json(),})
#---------------------------

0 comments on commit 5f3fa1a

Please sign in to comment.