예제 #1
0
def saveMovieInfo(filename, fileurl):
    db = sqlite3.connect("db.sqlite3")
    count = int(
        db.execute("SELECT count(*) from movies_movie").fetchall()[0][0])

    title = ""
    year = filename[len(filename) - 4:]
    try:
        int(year)
        title = filename[:len(filename) - 5]
    except:
        title = filename
        year = None

    if (dbutils.doesmovieexist(title, year)):
        return
    #TODO: https://docs.djangoproject.com/en/1.10/topics/db/queries/

    movtup = genMovieInfo(title, year, fileurl)
    #print(movtup)

    p = Movie(title=movtup[0],
              year=movtup[1],
              running_time_min=movtup[2],
              genre_one=movtup[3],
              genre_two=movtup[4],
              genre_three=movtup[5],
              imdb_rating=movtup[6],
              rating=movtup[7],
              description=movtup[8],
              img_url=movtup[9],
              file_url=movtup[10])
    p.save()
예제 #2
0
    def test_list_movies_one(self):
        movie_genre = MovieGenre(name='Comedy')
        movie_genre.save()

        User.objects.create_user('admin', '*****@*****.**', 'password123')
        movie = Movie(title="Movie 1")
        movie.save()

        client = APIClient()
        response = client.get('/api/movies', {})
        self.assertEqual(response.status_code, 200)

        self.assertEqual(response.data, [
            OrderedDict([
                ('id', 1),
                ('title', 'Movie 1'),
                ('summary', ''),
                ('release_year', 2018),
                ('director', ''),
                ('genre', 1),
                ('genre_obj', OrderedDict([('id', 1), ('name', 'Comedy')])),
                ('image', 'http://testserver/media/movies/Movie.jpg'),
                ('rating', 3),
                ('user', 1),
                ('user_obj', OrderedDict([('id', 1), ('username', 'admin')])),
                ('small_image',
                 'http://testserver/media/movies/small/Movie.jpg'),
            ])
        ])
예제 #3
0
    def test_edit_movie_cannot_edit_id(self):
        movie_genre = MovieGenre(name='Drama')
        movie_genre.save()

        movie = Movie(title="Movie 1")
        movie.save()

        User.objects.create_user('admin', '*****@*****.**', 'password123')

        client = APIClient()
        client.login(username='******', password='******')
        response = client.put(
            '/api/movies/' + str(movie.id), {
                'id': 5,
                'title': 'Movie 2',
                'summary': 'Lion Movie',
                'release_year': '1994',
                'rating': 2,
                'director': 'Roger Allers'
            })

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(Movie.objects.all()), 1)
        self.assertEqual(Movie.objects.get(id=movie.id).title, 'Movie 2')
        self.assertEqual(Movie.objects.get(id=movie.id).id, 1)
예제 #4
0
def clear(m: Movie, attr):
    with Recorder(note="Auto remove title") as r:
        r.record_update_before(m)
        setattr(m, attr, None)
        m.idea_modified = True
        m.save()
        r.record_update_after(m)
예제 #5
0
        class ContextSearch(
                Returns200, ):
            matching_movies = lambda_fixture(
                lambda: Movie.objects.bulk_create([
                    Movie(title='Forty-Two Monkeys', year=1997),
                ]))
            non_matching_movies = lambda_fixture(
                lambda: Movie.objects.bulk_create([
                    Movie(title="Alfred Hitchcock's The Byrds: A Biopic",
                          year=1975),
                ]))
            movies = lambda_fixture(
                lambda matching_movies, non_matching_movies:
                (matching_movies + non_matching_movies),
                autouse=True,
            )

            query_params = static_fixture({
                'q': 'monkey',
            })

            def it_returns_only_matching_movies(self, matching_movies,
                                                results):
                expected = express_movies(matching_movies)
                actual = results
                assert expected == actual
예제 #6
0
 def testDeleteExistingMovie(self):
     movie = Movie()
     movie.save()
     self.assertTrue(Movie.objects.filter(id=1).exists())
     response = self.client.delete('/movies/1/', follow=True)
     self.assertEqual(200, response.status_code)
     self.assertFalse(Movie.objects.filter(id=1).exists())
예제 #7
0
 def testInvalidValueChanged(self):
     new_movie = Movie(title="TestMovie")
     new_movie.save()
     response = self.client.put(new_movie.get_absolute_url(),
                                {"bad": "true"},
                                follow=True)
     self.assertEqual(400, response.status_code)
예제 #8
0
 def post(self, request, id=None):
     response = {}
     try:
         data = json.loads(request.body)
     except ValueError as e:
         response["status"] = 400
         response["info"] = "Failed to load JSON"
         return JsonResponse(response)
     if ("title" in data.keys() and "rating" in data.keys()):
         try:
             movie = Movie(title=data["title"], rating=data["rating"])
             movie.save()
             response["status"] = 200
             response["info"] = "Success"
             return JsonResponse(response)
         except Exception as e:
             print(e)
             response["status"] = 400
             response["info"] = "Unable to store information"
             return JsonResponse(response)
     else:
         response["status"] = 400
         response[
             "info"] = "Please use the following keys: title and rating"
         return JsonResponse(response)
예제 #9
0
def dodaj_film(request):
    if request.method == 'GET':
        return render(request, 'dodaj_film.html')
    tytul = request.POST.get('title')
    year = request.POST.get('year')
    m = Movie(title=tytul, year=year)
    m.save()
    return redirect("/filmy/")
예제 #10
0
 def testListUnfilteredComments(self):
     movie = Movie(title="1")
     movie.save()
     Comment.objects.bulk_create(
         [Comment(movie=movie, date="2000-01-01") for i in range(3)])
     response = self.client.get('/comments/')
     self.assertEqual(200, response.status_code)
     self.assertEqual(3, len(response.json()))
    def test_save_movies_to_watched(self):
        watched_movie = Movie(douban_id=1421721)
        watched_movie.save()
        _save_movies_to_watched(douban_watched_movies)

        movies = Movie.objects.all()

        self.assertEquals(len(movies), 1)
예제 #12
0
def _get_or_create_movie_object(douban_id):
    douban_id = int(douban_id)
    try:
        movie = Movie.objects.get(pk=douban_id)
    except Movie.DoesNotExist:
        movie = Movie(douban_id=douban_id)
        movie.save()
    return movie
예제 #13
0
    def handle(self, *args, **options):
        print("demo demo demo")

        print("Getting Datetime Information")
        now = datetime.datetime.now()
        dateSTR = datetime.date(day=now.day, month=now.month,
                                year=now.year).strftime('%A %d %B %Y')
        print("It is ", dateSTR)
        print("Getting Movies")
        url = 'http://www.ebroadcast.com.au/tv/movies'
        page = requests.get(url)
        htmlTxt = page.text

        times, names, channels = [], [], []

        print("Parsing Movies Into Tables")
        htmlBS = BeautifulSoup(htmlTxt, 'html.parser')
        table = htmlBS.find('table', class_="table table-hover").find('tbody')
        for row in table.findAll(
                'tr'):  # Iterates through each row in the table body
            # print(row.prettify())
            cells = row.findAll('td')
            times.append(cells[0].find('h5').text)
            names.append(cells[1].find('h5').text)
            if (cells[2].h5 == None):
                channels.append(cells[3].h5)
            else:
                channels.append(cells[2].h5)

        # Make it so that it just adds to same file, and add tha ir date in A column

        # b = names.__len__() + a
        # col = [x for x in range(a, b)]
        print("Adding Movies to Database")
        for x in range(names.__len__()):
            print("a")
            movie = Movie(movie_name=names[x],
                          channel=channels[x].text,
                          air_date=now.date(),
                          air_time=datetime.datetime.strptime(
                              times[x], '%I:%M %p'))
            movie.save()
            # num = col[x] + 2
            # ws['A' + str(num)] = dateSTR
            # ws['B' + str(num)] = times[x]
            # ws['C' + str(num)] = names[x]
            # ws['D' + str(num)] = channels[x].text

        # a += names.__len__()
        # ws['E1'] = a
        # print("Saving Spreadsheet")
        # wb.save('Movie.xlsx')
        print("\n\nScript has finished for",
              dateSTR + ". You can now open and view the spreadsheet.")
        print(
            "\n\nThis script will automatically run at 10:00am tomorrow if you leave this window open.\nOtherwise just run it again tomorrow, and it will add tomorrow's movies to the current spreadsheet."
        )
        print("\nMade by Liam Angus")
예제 #14
0
def test_movie_model():
    movie = Movie(title="Ciao bella", genre="comedy", year="1952")
    movie.save()
    assert movie.title == "Ciao bella"
    assert movie.genre == "comedy"
    assert movie.year == "1952"
    assert movie.created_date
    assert movie.updated_date
    assert str(movie) == movie.title
예제 #15
0
def test_movie_model():
    movie = Movie(title='Matrix', genre='action', year='1999')
    movie.save()
    assert movie.title == 'Matrix'
    assert movie.genre == 'action'
    assert movie.year == '1999'
    assert movie.created_date
    assert movie.updated_date
    assert str(movie) == movie.title
def test_movie_model():
    movie = Movie(title="Test Movie", genre="Test Genre", year="1980")
    movie.save()
    assert movie.title == "Test Movie"
    assert movie.genre == "Test Genre"
    assert movie.year == "1980"
    assert movie.created_date
    assert movie.updated_date
    assert str(movie) == movie.title
예제 #17
0
def test_movie_model():
    movie = Movie(title="Covid Space Attack 2022", genre="comedy", year="2021")
    movie.save()
    assert movie.title == "Covid Space Attack 2022"
    assert movie.genre == "comedy"
    assert movie.year == "2021"
    assert movie.created_date
    assert movie.updated_date
    assert str(movie) == movie.title
 def get_context_data(self, **kwargs):
     context = super(IndexView, self).get_context_data(**kwargs)
     context.update({
         'movie_attributes': zip(Movie.get_movie_attribute_keys(), Movie.get_movie_attribute_names()),
         'movie_attribute_names': Movie.get_movie_attribute_names(),
         'movie_attribute_keys': Movie.get_movie_attribute_keys(),
         'last_update': self.get_last_update()
     })
     return context
예제 #19
0
def test_movie_model():
    movie = Movie(title="Raising Arizona", genre="comedy", year="1987")
    movie.save()
    assert movie.title == "Raising Arizona"
    assert movie.genre == "comedy"
    assert movie.year == "1987"
    assert movie.created_date
    assert movie.updated_date
    assert str(movie) == movie.title
예제 #20
0
 def testRatingsChange(self):
     new_movie = Movie(title="TestMovie")
     new_movie.save()
     ratings_array = json.loads('[{"source": "s", "value": "v"}]')
     update_ratings_from_json(new_movie.id, ratings_array)
     ratings = Movie.objects.get(id=new_movie.id).rating_set.all()
     self.assertEqual(1, len(ratings))
     self.assertEqual("s", ratings.first().source)
     self.assertEqual("v", ratings.first().value)
예제 #21
0
    def test_multiple_movies(self):
        """
        one movie created, should return one element list
        """
        Movie(title='Test1').save()
        Movie(title='Test2').save()

        query = "query { allMovies { edges { node { id title } } } }"

        self.assertMatchSnapshot(self.client.execute(query))
예제 #22
0
    def test_movie_year_filter(self):
        """
        two movies created with different years, should return only one of them
        """
        Movie(title='Test1', year=1990).save()
        Movie(title='Test2', year=2005).save()

        query = "query { allMovies(year_Lt: 2000) { edges { node { id title year } } } }"

        self.assertMatchSnapshot(self.client.execute(query))
예제 #23
0
def test_movie_model():
    movie = Movie(title="Sample Movie", genre="comedy", year="1995")
    movie.save()

    assert movie.title == "Sample Movie"
    assert movie.genre == "comedy"
    assert movie.year == "1995"
    assert movie.created_at
    assert movie.updated_at
    assert str(movie) == movie.title
예제 #24
0
 def testTitleChange(self):
     new_movie = Movie(title="TestMovie")
     new_movie.save()
     new_title = 'NewTitle'
     payload = '{{"title": "{}"}}'.format(new_title)
     response = self.client.put(new_movie.get_absolute_url(),
                                payload,
                                follow=True)
     self.assertEqual(200, response.status_code)
     movie_from_db = Movie.objects.get(id=new_movie.id)
     self.assertEqual(new_title, movie_from_db.title)
예제 #25
0
    def test_delete_movie_not_logged_in(self):
        movie_genre = MovieGenre(name='Drama')
        movie_genre.save()

        movie = Movie(title="Movie 1")
        movie.save()

        client = APIClient()
        response = client.delete('/api/movies/' + str(movie.id))

        self.assertEqual(response.status_code, 403)
        self.assertEqual(len(Movie.objects.all()), 1)
예제 #26
0
 def mutate(root, info, input=None):
     ok = True
     actors = []
     for actor_input in input.actors:
         actor = Actor.objects.get(pk=actor_input.id)
         if actor is None:
             return CreateMovie(ok=False, movie=None)
         actors.append(actor)
     movie_instance = Movie(title=input.title, year=input.year)
     movie_instance.save()
     movie_instance.actors.set(actors)
     return CreateMovie(ok=ok, movie=movie_instance)
예제 #27
0
    def mutate(self, info, id, name, year, rating, category_id):
        movie = Movie(name=name,
                      year=year,
                      rating=rating,
                      category_id=category_id)
        movie.save()

        return CreateMovie(id=movie.id,
                           name=movie.name,
                           year=movie.year,
                           rating=movie.rating,
                           category_id=movie.category)
예제 #28
0
 def testRatingsChangeThroughPut(self):
     new_movie = Movie(title="TestMovie")
     new_movie.save()
     payload = json.dumps({"ratings": '[{"source": "s", "value": "v"}]'})
     response = self.client.put(new_movie.get_absolute_url(),
                                payload,
                                follow=True)
     self.assertEqual(200, response.status_code)
     ratings = Movie.objects.get(id=new_movie.id).rating_set.all()
     self.assertEqual(1, len(ratings))
     self.assertEqual("s", ratings.first().source)
     self.assertEqual("v", ratings.first().value)
예제 #29
0
 def post(self, request):
     movie = Movie()
     movie.user = request.user  # asignamos a la pelicula el usuario autenticado
     form = MovieForm(request.POST, instance=movie)
     if form.is_valid():
         movie = form.save()
         form = MovieForm()
         url = reverse('movie_detail_page', args=[movie.pk])
         message = "Movie created succesfully! "
         message += '<a href="{0}">View</a>'.format(url)
         messages.success(request, message)
     return render(request, 'movie_form.html', {'form': form})
예제 #30
0
 def post(self, request):
     movie = Movie()
     movie.user = request.user  # Asignamos el usuario autenticado
     form = MovieForm(request.POST, instance=movie)
     if form.is_valid():
         movie = form.save()
         form = MovieForm()
         url = reverse("movie_detail_page", args=[movie.pk])
         message = "Película guardada!"
         message += "<a href='{0}'>View</a>".format(url)
         messages.success(request, message)
     return render(request, "movie_form.html", {"form": form})
예제 #31
0
    def test_delete_movie_not_logged_in(self):
        movie_genre = MovieGenre(name='Drama')
        movie_genre.save()

        movie = Movie(title="Movie 1")
        movie.save()

        client = APIClient()
        response = client.delete('/api/movies/' + str(movie.id))

        self.assertEqual(response.status_code, 403)
        self.assertEqual(len(Movie.objects.all()), 1)
예제 #32
0
    def upsert_movie(movie_from_api):
        api_response = movie_from_api.json()
        movie_instance = Movie.objects.filter(
            title__iexact=api_response["Title"])

        if movie_instance:
            movie_instance = movie_instance[0]
        else:
            movie_instance = Movie()

        map_response_to_movie(movie_instance, api_response)
        movie_instance.save()
예제 #33
0
 def test_get_returns_all_comments(self):
     movie = Movie(title='Glass',
                   released=datetime.date(2000, 1, 1),
                   genre="Drama")
     movie.save()
     Comment(body='asd', movie=movie).save()
     response = self.client.get('/comments/')
     expected_response = [{
         'body': 'asd',
         'movie': 'Glass',
     }]
     self.assertEqual(response.json(), expected_response)
예제 #34
0
 def test_post_with_valid_data_creates_a_comment(self):
     movie = Movie(title='Glass',
                   released=datetime.date(2000, 1, 1),
                   genre="Drama")
     movie.save()
     old_comments_count = Comment.objects.count()
     self.client.post('/comments/', {
         'body': 'commented',
         'movie': movie.pk
     })
     new_comments_count = Comment.objects.count()
     self.assertEqual(old_comments_count + 1, new_comments_count)
예제 #35
0
 def writeModel(self, root, title, year, genre, source, cover, desc):
     obj = Movie()
     obj.title = title
     obj.year = year
     obj.genre = genre
     obj.source = source
     obj.cover = cover
     obj.description = desc
     obj.save()
예제 #36
0
 def test_adding_movie(self):
     movie = Movie(title_en='Terminator ver 1', title_he=u'טרמינטור אחד' )
     movie.imdb_rating = str(9.5)
     movie.save()
     
     self.assertEqual(unicode(movie.title_he), u'טרמינטור אחד')
 
     r = self.client.get(movie.get_absolute_url(), {})
     self.assertEqual(r.status_code, 200)
     obj = r.context['object']
     self.assertEqual(obj.title, u'Terminator ver 1')  
     self.assertEqual(obj.title_he, u'טרמינטור אחד')    
     self.assertEqual(obj.slug, u'terminator-ver-1')   
     self.assertEqual(float(obj.imdb_rating), 9.5 )
예제 #37
0
    def handle(self, *args, **options):
        for x in range(1, 8):
            name = 'Actor Number {num}'.format(num=x)
            Actor(name=name, date_of_birth=datetime.datetime.now().date()).save()

        for x in range(1, 6):
            title = 'a random movie about {num}'.format(num=x)
            movie = Movie(title=title, year_released=2012,
            description='a nice new movie from our friends at paramount')
            movie.save()

            for actor in Actor.objects.all().order_by('?')[:2]:
                movie.actors.add(actor)
            movie.save()
예제 #38
0
파일: views.py 프로젝트: amni/Netflexxed
def index(request):
	if (len(Movie.objects.filter(name="The Matrix"))==0):
		movie= Movie(name="The Matrix", url="http://movies2.netflix.com/WiPlayer?movieid=20557937&amp;trkid=50000009&amp;t=The%2BMatrix&amp;tctx=-99%2C-99%2Ccbd7a870-c1dd-40cc-b08a-181cd7ed85c1-1509012", pic_url="http://cdn0.nflximg.net/images/1050/1691050.jpg", critics_score=87, audience_score=82)
		movie.save()
	movies=Movie.objects.order_by('critics_score').reverse()
	review_map=[]
	for movie in movies:
		review_map.append(movie.name)
		review_map.append(movie.id)

	json_data= simplejson.dumps([movie.name for movie in movies], indent=4)
	json_data2= simplejson.dumps(review_map, indent=4)
	t = get_template('index.html')
	html = t.render(Context({'movies':movies, 'critically_acclaimed':movies[:30],'fan_favorites':Movie.objects.order_by('audience_score')[:15], 'not_in_america': [movie for movie in movies if movie.is_american==False], 'movie_json':json_data, 'reviews':review_map, 'name_to_id_map':json_data2}))
	return HttpResponse(html)
예제 #39
0
    def test_delete_movie(self):
        movie_genre = MovieGenre(name='Drama')
        movie_genre.save()

        movie = Movie(title="Movie 1")
        movie.save()

        User.objects.create_user('admin', '*****@*****.**', 'password123')

        client = APIClient()
        client.login(username='******', password='******')
        response = client.delete('/api/movies/' + str(movie.id))

        self.assertEqual(response.status_code, 204)
        self.assertEqual(len(Movie.objects.all()), 0)
예제 #40
0
def seed_users_movies():

    for num in range(1, 100):
        def random_sex():
            if random.randint(1, 2) == 1:
                return "M"
            else:
                return "F"
        age = random.randint(18, 100)
        occupation = random.randint(0,20)
        new_rater = Rater(num, random_sex(), age, occupation)
        new_rater.save()

        movie_name = fake.name()
        movie_genre = fake.bs()
        new_movie = Movie(num, movie_name, movie_genre)
        new_movie.save()
예제 #41
0
    def test_edit_movie(self):
        movie_genre = MovieGenre(name='Drama')
        movie_genre.save()

        movie = Movie(title="Movie 1")
        movie.save()

        User.objects.create_user('admin', '*****@*****.**', 'password123')

        client = APIClient()
        client.login(username='******', password='******')
        response = client.put('/api/movies/' + str(movie.id), {'title': 'Movie 2',
                                                               'summary': 'Lion Movie',
                                                               'release_year': '1994',
                                                               'rating': 2,
                                                               'director': 'Roger Allers'})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(Movie.objects.all()), 1)
        self.assertEqual(Movie.objects.get(id=movie.id).title, 'Movie 2')
예제 #42
0
파일: views.py 프로젝트: amni/Netflexxed
def test(request):
	titles=[]
	img_locations=[]
	movie_locations=[]

	extract_movies(titles, img_locations, movie_locations)

	for i in range(len((titles))):
		# print(titles[i])
		# print(movie_locations[i])
		# print(img_locations[i])
		if (len(Movie.objects.filter(name=titles[i]))==0 and titles[i]!='LOL'):
			if (len(RT(RT_KEY).search(titles[i]))>0 and RT(RT_KEY).search(titles[i])[0]['ratings']['critics_score']!=-1):
					critics_score= RT(RT_KEY).search(titles[i])[0]['ratings']['critics_score']
					audience_score=RT(RT_KEY).search(titles[i])[0]['ratings']['audience_score']
					movie = Movie(name=titles[i], url=movie_locations[i]+'?country='+country, pic_url=img_locations[i], country=country, is_american=False, audience_score=audience_score, critics_score=critics_score)
					movie.save()
					# get_rotten_tomates()
			else:
				movie = Movie(name=titles[i], url=movie_locations[i]+'?country='+country, pic_url=img_locations[i], country=country, is_american=False)
				movie.save()
			# if (len(RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i]))>0 and RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i])[0]['ratings']['critics_score']!=-1):
			# 		critics_score= RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i])[0]['ratings']['critics_score']
			# 		audience_score=RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i])[0]['ratings']['audience_score']
			# 		movie = Movie(name=titles[i], url=movie_locations[i]+'?country='+country, pic_url=img_locations[i], country=country, is_american=False, audience_score=audience_score, critics_score=critics_score)
			# 		movie.save()
			# else:
		get_rotten_tomates()
	t = get_template('index.html')
	html = t.render(Context({}))
	return HttpResponse(html)
예제 #43
0
    def generateNewEntry(self, hash, filename, element):
        print "Adding: " + hash + " File: " + filename
        if hash == "":
            print " file skipped, because no hash was found"
            return

        movie = Movie(
            title = hash,
            slug = hash
        )
        movie.save()
        scene = Scene(
            sha256 = hash,
            movie = movie,
            title = os.path.basename(filename),
            animatedImage = hash + ".gif",
            stillImage = hash + ".png",
            sceneRelPath = filename,
            duration = int(element.xpath("duration/text()")[0])
        )
        scene.save()
        return
예제 #44
0
    def test_list_movies_one(self):
        movie_genre = MovieGenre(name='Comedy')
        movie_genre.save()

        User.objects.create_user('admin', '*****@*****.**', 'password123')
        movie = Movie(title="Movie 1")
        movie.save()

        client = APIClient()
        response = client.get('/api/movies', {})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [OrderedDict([('id', 1),
                                                      ('title', 'Movie 1'),
                                                      ('summary', ''),
                                                      ('release_year', 2016),
                                                      ('director', ''),
                                                      ('genre', 1),
                                                      ('genre_obj', OrderedDict([('id', 1),
                                                                                 ('name', 'Comedy')])),
                                                      ('image', 'http://testserver/media/movies/Movie.jpg'),
                                                      ('rating', 3),
                                                      ('user', 1),
                                                      ('user_obj', OrderedDict([('id', 1),
                                                                                ('username', 'admin')]))])])
예제 #45
0
    def create_or_update_movie_from_line(self, line):
        movie_parts_separator = "  "

        self.stdout.write(u'Processing line {line}'.format(line=line))

        movie_line_parts = filter(None, (line.split(movie_parts_separator)))

        title = movie_line_parts[3].split("\" (")[0][1:]
        year = movie_line_parts[3].split("\" (")[1][:-2]

        new_or_updated_movie = Movie()
        new_or_updated_movie.imdb_rank = float(movie_line_parts[2])
        new_or_updated_movie.title = title
        new_or_updated_movie.year = year
        new_or_updated_movie.imdb_votes = int(movie_line_parts[1])
        new_or_updated_movie.rating = new_or_updated_movie.imdb_rank
        new_or_updated_movie.total_votes = new_or_updated_movie.imdb_votes
        new_or_updated_movie.save()

        self.stdout.write(unicode(new_or_updated_movie))
        self.stdout.write('')
예제 #46
0
 def movies(filename):
     data = readfile(filename, '|', encode='ISO-8859-1')        
     from dateutil.parser import parse
     
     for line in data:                              
         movie_data = line[0:5]
         print(movie_data)
         rating = line[5:]
         print(rating)
         movies = Movie()
         movies.movie_id = line[0]
         movies.title = line[1]
         movies.release_date = parse(line[2]).strftime('%Y-%m-%d')
         movies.video_release_date =  parse(line[3]).strftime('%Y-%m-%d')
         movies.imdb_url = line[4]
         movies.save()
         for idx, rate in enumerate(rating):
             if int(rate) == 1:
                 movies.genre.add(get_genre_object(idx))
예제 #47
0
    def createMovie(self, response):
        # save results in the database
        for rawitem in response['results']:
            # avoid request limits
            time.sleep(1)

            print "Saving %s" % rawitem['title']
            
            # ask for details about the movie
            item = self.createRequest( "get", "/movie/%s" % rawitem['id'], {
                "api_key" : self.api_key,
                "append_to_response" : "videos"
            })
            
            # collect genres ids
            genres = item['genres']
            genresNew = []
            item['genres'] = []
            for genre in genres:
                try:
                    genredb = MovieGenres.objects.get(name=genre['name'])
                except MovieGenres.DoesNotExist:
                    genredb = MovieGenres( name=genre['name'], url=slugify(genre['name']) )
                    genredb.save()

                genresNew.append(genredb.id)
            
            item['url'] = slugify( item['title'] )

            # trailer
            trailer_youtube_url = None
            if "results" in item['videos']: 
                for video in item['videos']['results']:
                    if ( video['type'].lower()=="trailer" and video['site'].lower()=="youtube" ):
                        trailer_youtube_url = video['key']
                        break

            if trailer_youtube_url != None:
                item['trailer_youtube_url'] = trailer_youtube_url
            else:
                continue

            # create/update movie
            try:
                movie = Movie.objects.get( url=item['url'] )
            except Movie.DoesNotExist:
                movie = Movie()
            
            Movie.createFromJSON( movie, item )
            movie.save()

            # add genres
            movie.genres = genresNew
            
            # add image
            movie.poster_image_ext = self.imgConfig['base_url'] + 'w185' + item['poster_path']

            # save
            movie.save()

            print "... Saved"
예제 #48
0
    def handle(self, *args, **options):
        FILE_NAME = base.BASE_DIR + '/movie_movies_data.pickle'
        # Load the dictionary back from the pickle file.
        print(base.BASE_DIR)
        data_list = pickle.load(open(FILE_NAME, "rb"))
        
        for data in data_list:
            try:
                title = re.sub("[\(\[].*?[\)\]]", "",data['film_name']['value']).strip() 
            except:
                title = None
            try:
                value = data['film_director']['value']
                if ',' in value :
                    director_list = value.split(',')
                else:
                    director_list = []
                    director_list.append(value) 
            except:
                director_list = None
            try:
                value = data['film_writer']['value']
                if ',' in value :
                    writer_list = value.split(',')
                else:
                    writer_list = []
                    writer_list.append(value)
            except:
                writer_list = []
            try:
                value = data['actor_name']['value']
                if ',' in value :
                    actor_list = value.split(',')
                else:
                    actor_list = []
                    actor_list.append(value)     
            except:
                actor_list = []
            try:
                value = data['film_producer']['value']
                if ',' in value :
                    producer_list = value.split(',')
                else:
                    producer_list = []
                    producer_list.append(value)
            except:
                producer_list = []
            try:
                value = data['film_screenplay']['value']
                if ',' in value :
                    screenplay_list = value.split(',')
                else:
                    screenplay_list = []
                    screenplay_list.append(value)
            except:
                screenplay_list = []
            editing_list = []
            try:
                value = data['film_editing']['value']
                if ',' in value :
                    editing_list = value.split(',')
                else:
                    editing_list = []
                    editing_list.append(value)
            except:
                editing_list = []

            try:
                value = data['film_cinematography']['value']
                if ',' in value :
                    cinematography_list = value.split(',')
                else:
                    cinematography_list = []
                    cinematography_list.append(value)
            except:
                cinematography_list = []
            
            try:
                value = data['film_musicComposers']['value']
                if ',' in value :
                    musicComposers_list = value.split(',')
                    
                else:
                    musicComposers_list = []
                    musicComposers_list.append(value)
            except:
                musicComposers_list = []
            try:
                description_list = data['film_abstract']['value']
            except:
                description_list = []
            try:
                wikiPageUrl_list = "https://en.wikipedia.org/wiki/index.html?curid=" + data['film_wikiPageID']['value']
            except:
                wikiPageUrl_list = []


            # mlist = Movie(titel = title , directors = director_list, writers = writer_list, 
            #           actors = actor_list, producer = producer_list, 
            #           screenplay = screenplay_list, editing = editing_list,
            #           cinematography = cinematography_list, musicComposers = musicComposers_list,
            #           description = description_list, wikiPageUrl = wikiPageUrl_list
            #   )
            if not Movie.objects.filter(title__iexact = title).exists():
                mlist = Movie(title = title , 
                          description = description_list, wikiPageUrl = wikiPageUrl_list
                  )
                mlist.save()
            else: 
                mlist= Movie.objects.get(title = title)
            
            for d in director_list:
                if not Person.objects.filter(fullname__iexact = d).exists():
                    try:
                        d.split(' ')[1]
                    except:
                        continue
                    if len(d.split(' ')) == 2 :
                        p = Person(fullname=d, firstname=d.split(' ')[0], lastname=d.split(' ')[1])
                        p.save()
                        o_object = Occupation.objects.get(title = 'director')
                        p.occupations.add(o_object)
                    elif len(d.split(' ')) > 2 :
                else:
                    dp = Person.objects.get(fullname = d)
                    mlist.directors.add(dp)

            for w in writer_list:
                if not Person.objects.filter(fullname__iexact = w).exists():
                    try:
                        w.split(' ')[1]
                    except:
                        continue
                    p = Person(fullname=w, firstname=w.split(' ')[0], lastname=w.split(' ')[1])
                    p.save()
                    o_object = Occupation.objects.get(title = 'writer')
                    p.occupations.add(o_object)
                else:
                    wp = Person.objects.get(fullname = w)
                    mlist.writers.add(wp)

            for a in actor_list:
                if not Person.objects.filter(fullname__iexact = a).exists():
                    try:
                        a.split(' ')[1]
                    except:
                        continue
                    p = Person(fullname=a, firstname=a.split(' ')[0], lastname=a.split(' ')[1])
                    p.save()
                    o_object = Occupation.objects.get(title = 'actor')
                    p.occupations.add(o_object)
                else:
                    pass
                    #ap = Person.objects.get(fullname = a)
                    #mlist.actors(ap)

            for p in producer_list:
                if not Person.objects.filter(fullname__iexact = p).exists():
                    try:
                        p.split(' ')[1]
                    except:
                        continue
                    pe = Person(fullname=p, firstname=p.split(' ')[0], lastname=p.split(' ')[1])
                    pe.save()
                    o_object = Occupation.objects.get(title = 'producer')
                    pe.occupations.add(o_object)
                else:
                    pp = Person.objects.get(fullname = p)
                    print(pp)
                    mlist.producers.add(pp)

            for s in screenplay_list:
                if not Person.objects.filter(fullname__iexact = s).exists():
                    try:
                        s.split(' ')[1]
                    except:
                        continue
                    p = Person(fullname=s, firstname=s.split(' ')[0], lastname=s.split(' ')[1])
                    p.save()
                    o_object = Occupation.objects.get(title = 'screenplay')
                    p.occupations.add(o_object)
                else:
                    sp = Person.objects.get(fullname = s)
                    mlist.screenplays.add(sp)

            for e in editing_list:
                if not Person.objects.filter(fullname__iexact = e).exists():
                    try:
                        e.split(' ')[1]
                    except:
                        continue
                    p = Person(fullname=e, firstname=e.split(' ')[0], lastname=e.split(' ')[1])
                    p.save()
                    o_object = Occupation.objects.get(title = 'editing')
                    p.occupations.add(o_object)
                else:
                    ep = Person.objects.get(fullname = e)
                    mlist.editing.add(ep)

            for c in cinematography_list:
                if not Person.objects.filter(fullname__iexact = c).exists():
                    try:
                        c.split(' ')[1]
                    except:
                        continue
                    p = Person(fullname=c, firstname=c.split(' ')[0], lastname=c.split(' ')[1])
                    p.save()
                    o_object = Occupation.objects.get(title = 'cinematography')
                    p.occupations.add(o_object)
                else:
                    cp = Person.objects.get(fullname = c)
                    mlist.cinematography.add(cp)

            for m in musicComposers_list:
                if not Person.objects.filter(fullname__iexact = m).exists():
                    try:
                        m.split(' ')[1]
                    except:
                        continue
                    p = Person(fullname=m, firstname=m.split(' ')[0], lastname=m.split(' ')[1])
                    p.save()
                    o_object = Occupation.objects.get(title = 'music composer')
                    p.occupations.add(o_object)
                else:
                    mp = Person.objects.get(fullname = m)
                    mlist.musicComposers.add(mp)
예제 #49
0
    def get_folder_names_and_save_to_model(self):
        folderlist = open("data/folders")
        
        # Create the object that will be used to access the IMDb's database.
        ia = imdb.IMDb() # by default access the web.
        
        try:
            for moviefolder in folderlist:
                if("-" in moviefolder):
                    print
                    print "End of folders"
                    break

                print "Analyzing folders: ", moviefolder
                print "Movies: "

                for movie in os.listdir(moviefolder.rstrip()):
                    movie_content = movie.split(" ++ ")
                    print movie_content
                    
                    movie_name = movie_content[0]
                    try:
                        movie_languages = movie_content[1] 
                        movie_quality = movie_content[2]
                    except: 
                        movie_languages = "no language provided"
                        movie_quality = "no quality provided"
                    print "Name: %s  Languages: %s  Quality: %s" % (movie_name, movie_languages, movie_quality)
                    
                    #movie_db = Movie(name=movie_name, languages=movie_languages, quality=movie_quality, in_folder=moviefolder)
                    #movie_db.save()

                    ''' 
                        IMDB Access and retriving of movie data
                        TODO: auslagern
                    '''
                    # Search for a movie (get a list of Movie objects).
                    s_result = ia.search_movie(movie_name)
                    if not s_result:
                        print "LALALAL"
                        movie_db = Movie(name=movie_name, imdb_name="Kein IMDb Eintrag gefunden", languages=movie_languages, quality=movie_quality, in_folder=moviefolder)
                        movie_db.save()
                        continue
                    
                    # Print the long imdb canonical title and movieID of the results.
                    #for item in s_result:
                    #    print item['long imdb canonical title'], item.movieID
                    
                    # Retrieves default information for the first result (a Movie object).
                    imdb_movie_obj = s_result[0]
                    ia.update(imdb_movie_obj)
                    
                    # Print some information.
                    try:
                        imdb_name=imdb_movie_obj
                        print "Imdb name: ", imdb_name
                        
                    except:
                        imdb_name = "No name is found in imdb."
                    
                    try:
                        runtime=imdb_movie_obj['runtime'][0]
                        print "Imdb runtime(in min): ", runtime
                        
                    except:
                        runtime = 0
                        
                    try:
                        rating=imdb_movie_obj['rating']
                        print "Imdb rating: ", rating
                        
                    except:
                        rating = 0
                    
                    try:
                        plot=imdb_movie_obj['plot'][0]
                        print "Imdb plot: ", plot
                        
                    except:
                        plot = "No plot is found in imdb."


                    #director = imdb_movie_obj['director'] # get a list of Person objects.

                    '''
                        END OF IMDB Data migration
                    '''
                    
                    movie_db = Movie(name=movie_name,imdb_name= imdb_name, description=plot, imdb_rating=rating, length=runtime, languages=movie_languages, quality=movie_quality, in_folder=moviefolder)
                    movie_db.save()

                print
        except OSError:
            print "Wrong movie folder: ", moviefolder
예제 #50
0
파일: feedgotv.py 프로젝트: duyvk/GTVRec
 def to_movie_model(self):
     mm = Movie(movieID=self.movieId)
     # update foreign key
     location = None
     if self.location:
         location = create_region(self.location, self.location_name, 'movie')
     # update m2m
     genres = []
     if self.subcates:
         for i in range(len(self.subcates)):
             subcate = self.subcates[i]
             subcate_name = ''
             if self.subcates_name:
                 try:
                     subcate_name = self.subcates_name[i]
                 except:
                     subcate_name = ''
             genre = create_genre(subcate, subcate_name, 'movie')
             genres.append(genre)
         #mm.subcategory.add(genres)
     
     manufacs = []
     if self.manufacturers:
         for i in range(len(self.manufacturers)):
             manufacturerName = self.manufacturers[i]
             manufac = create_manufacturer(manufacturerName, 'movie')
             manufacs.append(manufac)
         #mm.manufacturers.add(manufacs)
     
     coworkers = []
     if self.directors:
         for i in range(len(self.directors)):
             personName = self.directors[i]
             person = create_people(None, personName, 'director', 'movie')
             coworkers.append(person)
         #mm.directors.add(coworkers)
     
     casts = []
     if self.casts:
         for i in range(len(self.casts)):
             cast = self.casts[i]
             person = create_people(None, cast, 'cast', 'movie')
             casts.append(person)
         #mm.casts.add(casts)
     
     tags = []
     if self.tags:
         for i in range(len(self.tags)):
             the_tag = self.tags[i]
             tag = create_tag(the_tag, 'movie')
             tags.append(tag)
         #mm.tags.add(tags)
     
     # update fields
     mm.movie_name = self.movie_name
     if self.isSingle is not None:
         mm.is_single_movie = self.isSingle
     if self.imdb is not None:
         mm.IMDB_score = self.imdb
     if self.size is not None:
         mm.size = self.size
     if self.isHD is not None:
         mm.is_HD = self.isHD
     if self.release_year is not None:
         mm.release_year = self.release_year
     if self.isPayment:
         mm.payment = self.isPayment
     if self.isDrama:
         mm.movie_type = 'drama'
     elif self.isCinema:
         mm.movie_type = 'cinema'
     else:
         mm.movie_type = None
     mm.image_url = self.image_url
     if self.view_count is not None:
         mm.view_count = self.view_count
     
     return (mm, {
                  'location':location,
                 },
                 {'genres': genres, 
                  'manufacs': manufacs, 
                  'coworkers': coworkers, 
                  'casts': casts, 
                  'tags': tags,
                  })