-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from jazzify/feature/auto-scrape
Create a command to scrape news platforms, also fix some dependencies
- Loading branch information
Showing
7 changed files
with
36 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
PyYAML==5.1.2 | ||
coreapi==2.3.3 | ||
black==19.3b0 | ||
pylint==2.4.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
from scraper.services import ScraperManager | ||
|
||
class Command(BaseCommand): | ||
help = 'Scrape the news platforms' | ||
|
||
def handle(self, *args, **options): | ||
scraper_manager = ScraperManager() | ||
errors = scraper_manager.run_requests() | ||
|
||
self.stdout.write(self.style.ERROR(f'Scraping errors "{errors}"')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
from django.shortcuts import render | ||
from rest_framework import viewsets, status | ||
from rest_framework.decorators import action | ||
from rest_framework import viewsets | ||
from rest_framework.response import Response | ||
|
||
from scraper.models import Post | ||
from scraper.serializers import PostSerializer | ||
from scraper.services import ScraperManager | ||
|
||
|
||
class PostViewSet(viewsets.ModelViewSet): | ||
queryset = Post.objects.all()[:10] | ||
queryset = Post.objects.all() | ||
serializer_class = PostSerializer | ||
|
||
@action(detail=False, methods=["get"]) | ||
def scrape_websites(self, request): | ||
scraper_manager = ScraperManager() | ||
errors = scraper_manager.run_requests() | ||
def list(self, request, *args, **kwargs): | ||
queryset = self.get_queryset()[:10] | ||
|
||
if errors: | ||
return Response({"errors": errors}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) | ||
else: | ||
return Response(status=status.HTTP_200_OK) | ||
serializer = self.get_serializer(queryset, many=True) | ||
return Response(serializer.data) |