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.
Also view the api on api/tv_shows Closes #32
- Loading branch information
shrikrishna
committed
Apr 16, 2018
1 parent
712475b
commit 648f09f
Showing
14 changed files
with
156 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
'python_libraries', | ||
'singers', | ||
'songs', | ||
'tv_shows', | ||
'writers', | ||
'rest_framework', | ||
] | ||
|
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
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,4 @@ | ||
from django.contrib import admin | ||
from tv_shows.models import TvShow | ||
|
||
admin.site.register(TvShow) |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TvShowsConfig(AppConfig): | ||
name = 'tv_shows' |
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,45 @@ | ||
from requests_html import HTMLSession | ||
|
||
from tv_shows.models import TvShow | ||
|
||
session = HTMLSession() | ||
r = session.get('http://www.imdb.com/list/ls004729995/?sort=moviemeter,asc&st_dt=&mode=detail&page=1') | ||
tv_shows = r.html.find('.lister-item') | ||
|
||
|
||
def import_data(i, tv_show): | ||
try: | ||
rank = i | ||
name = tv_show.find('h3')[0].find('a')[0].text | ||
url = ('http://www.imdb.com' | ||
+ tv_show.find('h3')[0].find('a')[0].attrs.get('href')) | ||
summary = tv_show.find('p')[1].text | ||
rating = tv_show.find('strong')[0].text | ||
image_url = tv_show.find('img')[0].attrs.get('loadlate') | ||
genre = tv_show.find('.genre')[0].text | ||
duration = tv_show.find('.runtime')[0].text | ||
actors_and_directors = tv_show.find('.text-muted')[2].text | ||
votes_and_gross = tv_show.find('.text-muted')[3].text | ||
other_info = tv_show.find('.list-description')[0].text | ||
except Exception as ex: | ||
print(str(ex)) | ||
try: | ||
c, created = TvShow.objects.get_or_create( | ||
rank=rank, | ||
url=url, | ||
name=name, | ||
summary=summary, | ||
image_url=image_url, | ||
rating=rating, | ||
genre=genre, | ||
duration=duration, | ||
actors_and_directors=actors_and_directors, | ||
votes_and_gross=votes_and_gross, | ||
other_info=other_info, | ||
) | ||
if created: | ||
c.save() | ||
print('\nTvShow, {}, has been saved.'.format(c)) | ||
except Exception as ex: | ||
print('\n\nSomething went wrong saving this tv_show: {}\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 tv_shows.get_tv_shows import tv_shows, import_data | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Import movies data' | ||
|
||
TV_SHOWS = staticmethod(tv_shows) | ||
IMPORT_DATA = staticmethod(import_data) | ||
|
||
def handle(self, *args, **options): | ||
i = 1 | ||
for tv_show in self.TV_SHOWS: | ||
self.IMPORT_DATA(i, tv_show) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.12 on 2018-04-16 05:03 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='TvShow', | ||
fields=[ | ||
('rank', models.IntegerField(primary_key=True, serialize=False)), | ||
('name', models.CharField(max_length=300, null=True)), | ||
('url', models.URLField(null=True)), | ||
('summary', models.TextField(null=True)), | ||
('image_url', models.URLField(null=True)), | ||
('rating', models.FloatField(null=True)), | ||
('year_of_release', models.CharField(max_length=100, null=True)), | ||
('genre', models.TextField(null=True)), | ||
('duration', models.CharField(max_length=100, null=True)), | ||
('actors_and_directors', models.TextField(null=True)), | ||
('votes_and_gross', models.TextField(null=True)), | ||
('other_info', models.TextField(null=True)), | ||
], | ||
), | ||
] |
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,19 @@ | ||
from django.db import models | ||
|
||
|
||
class TvShow(models.Model): | ||
rank = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=300, null=True) | ||
url = models.URLField(null=True) | ||
summary = models.TextField(null=True) | ||
image_url = models.URLField(null=True) | ||
rating = models.FloatField(null=True) | ||
year_of_release = models.CharField(max_length=100, null=True) | ||
genre = models.TextField(null=True) | ||
duration = models.CharField(max_length=100, null=True) | ||
actors_and_directors = models.TextField(null=True) | ||
votes_and_gross = models.TextField(null=True) | ||
other_info = models.TextField(null=True) | ||
|
||
def __str__(self): | ||
return self.name |
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 TvShowSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = models.TvShow | ||
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('^tv_shows/$', views.ListTvShow.as_view()), | ||
url('^tv_show/(?P<pk>\d+)/$', views.DetailTvShow.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 ListTvShow(generics.ListCreateAPIView): | ||
queryset = models.TvShow.objects.all() | ||
serializer_class = serializers.TvShowSerializer | ||
|
||
|
||
class DetailTvShow(generics.RetrieveUpdateDestroyAPIView): | ||
queryset = models.TvShow.objects.all() | ||
serializer_class = serializers.TvShowSerializer |