Ejemplo n.º 1
0
def compute_trending(test, **kwargs):
    if test:
        logger.debug("get_trending task")
        return

    trendings_movies = []

    torrents_manager = TorrentsManager(config, PDbManager,
                                       CATEGORY_NAME['movies'])

    try:
        with db_factory.get_instance():
            # trendings_torrents = PDbManager.get_trending_torrents_by_category(Torrent._CAT_MOVIE, mindate, maxdate, delta_hours)
            trendings_torrents = torrents_manager.torrents_trending
        trendings_movies = movies_from_torrents(
            [t for t, _, _ in trendings_torrents])
    except ValueError as err:
        logger.warning(err)
        return

    with db_factory.get_instance():
        for movie in trendings_movies:
            try:
                PDbManager.imdb_object_to_db(movie, update=True)
            except Exception as err:
                logger.error('Error during imdb object creation (%s): %s' %
                             (movie.imdb_id, err))
Ejemplo n.º 2
0
 def test_imdb_object_to_db(self):
     imdb_objs = self.movies
     for idx, imdb_obj in enumerate(imdb_objs):
         db_imdb_obj, torrents_updated = PDbManager.imdb_object_to_db(imdb_obj)
         self.assertIsInstance(db_imdb_obj, PIMDBObject)
         self.assertEqual(torrents_updated, 0)
         if db_imdb_obj.genres:
             self.assertEqual(self.movies[idx].genres, db_imdb_obj.genres.split(';'))
Ejemplo n.º 3
0
 def test_imdb_object_to_db_with_torrents(self):
     movie = self.movies[0]
     movie.torrents = self.torrents[1:]
     db_imdb_obj, torrents_updated = PDbManager.imdb_object_to_db(movie)
     self.assertIsInstance(db_imdb_obj, PIMDBObject)
     self.assertEqual(torrents_updated, 2)
Ejemplo n.º 4
0
 def test_imdb_object_to_db_already_exist(self):
     db_imdb_obj, torrents_updated = PDbManager.imdb_object_to_db(self.movies[0])
     self.assertIsInstance(db_imdb_obj, PIMDBObject)
     self.assertEqual(torrents_updated, 0)