This repository has been archived by the owner on Jul 23, 2020. It is now read-only.
-
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 #34 from sks444/random
Import 100 best directors of all time
- Loading branch information
Showing
10 changed files
with
100 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django.contrib import admin | ||
from directors.models import Director | ||
|
||
admin.site.register(Director) |
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,34 @@ | ||
from requests_html import HTMLSession | ||
|
||
from directors.models import Director | ||
|
||
session = HTMLSession() | ||
r = session.get('http://www.imdb.com/list/ls056848274/') | ||
directors = r.html.find('.lister-item') | ||
|
||
|
||
def import_data(i, director): | ||
try: | ||
rank = i | ||
url = director.absolute_links.pop() | ||
name = director.find('a')[1].text | ||
best_movie = director.find('a')[2].text | ||
summary = director.find('p')[1].text | ||
image_url = director.find('img')[0].attrs.get('src') | ||
except Exception as ex: | ||
print(str(ex)) | ||
try: | ||
c, created = Director.objects.get_or_create( | ||
rank=rank, | ||
url=url, | ||
name=name, | ||
best_movie=best_movie, | ||
summary=summary, | ||
image_url=image_url, | ||
) | ||
if created: | ||
c.save() | ||
print('\nDirector, {}, has been saved.'.format(c)) | ||
except Exception as ex: | ||
print('\n\nSomething went wrong saving this director: {}\n{}' | ||
.format(name, str(ex))) |
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,16 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from directors.get_directors import directors, import_data | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Import Directors data' | ||
|
||
DIRECTORS = staticmethod(directors) | ||
IMPORT_DATA = staticmethod(import_data) | ||
|
||
def handle(self, *args, **options): | ||
i = 1 | ||
for director in self.DIRECTORS: | ||
self.IMPORT_DATA(i, director) | ||
i = i + 1 |
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
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,8 @@ | ||
from rest_framework import serializers | ||
from . import models | ||
|
||
|
||
class DirectorSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = models.Director | ||
fields = '__all__' |
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,8 @@ | ||
from django.conf.urls import url | ||
|
||
from . import views | ||
|
||
urlpatterns = [ # Ignore PycodestyleBear (W605) | ||
url('^directors/$', views.ListDirector.as_view()), | ||
url('^director/(?P<pk>\d+)/$', views.DetailDirector.as_view()), | ||
] |
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,15 @@ | ||
# todos/views.py | ||
from rest_framework import generics | ||
|
||
from . import models | ||
from . import serializers | ||
|
||
|
||
class ListDirector(generics.ListCreateAPIView): | ||
queryset = models.Director.objects.all() | ||
serializer_class = serializers.DirectorSerializer | ||
|
||
|
||
class DetailDirector(generics.RetrieveUpdateDestroyAPIView): | ||
queryset = models.Director.objects.all() | ||
serializer_class = serializers.DirectorSerializer |
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