Пример #1
0
def _tryFromCache(fromType, toType, id):
    #Return a tuple of a boolean which indicates if a cache entry was found and the cache entry or None
    #This way we will know if a cache entry exists or the cached value is None
    try:
        if fromType == "tvrage":
            id = TvIdCache.get(TvIdCache.tvrage == id)
        elif fromType == "tvdb":
            id = TvIdCache.get(TvIdCache.tvdb == id)
        elif fromType == "tvmaze":
            id = TvIdCache.get(TvIdCache.tvmaze == id)
        elif fromType == "imdb":
            id = MovieIdCache.get(MovieIdCache.imdb == id)
        elif fromType == "tmdb":
            id = MovieIdCache.get(MovieIdCache.tmdb == id)
        else:
            return False, None
    except (TvIdCache.DoesNotExist, MovieIdCache.DoesNotExist):
        return False, None
    if toType == "tvdb":
        return True, id.tvdb
    elif toType == "tvrage":
        return True, id.tvrage
    elif toType == "tvmaze":
        return True, id.tvmaze
    elif toType == "imdb":
        return True, id.imdb
    elif toType == "tmdb":
        return True, id.tmdb
    else:
        return False, None
Пример #2
0
def _tryFromCache(fromType, toType, id):
    #Return a tuple of a boolean which indicates if a cache entry was found and the cache entry or None
    #This way we will know if a cache entry exists or the cached value is None 
    try:
        if fromType == "tvrage":
            id = TvIdCache.get(TvIdCache.tvrage == id)
        elif fromType == "tvdb":
            id = TvIdCache.get(TvIdCache.tvdb == id)
        elif fromType == "tvmaze":
            id = TvIdCache.get(TvIdCache.tvmaze == id)
        elif fromType == "imdb":
            id = MovieIdCache.get(MovieIdCache.imdb == id)
        elif fromType == "tmdb":
            id = MovieIdCache.get(MovieIdCache.tmdb == id)
        else:
            return False, None
    except (TvIdCache.DoesNotExist, MovieIdCache.DoesNotExist):
        return False, None
    if toType == "tvdb":
        return True, id.tvdb
    elif toType == "tvrage":
        return True, id.tvrage
    elif toType == "tvmaze":
        return True, id.tvmaze
    elif toType == "imdb":
        return True, id.imdb
    elif toType == "tmdb":
        return True, id.tmdb
    else:
        return False, None
Пример #3
0
def _cacheTvMazeIds(tvMaze):
    try:
        cacheEntry = TvIdCache(tvmaze=tvMaze.tvmazeid, tvrage=tvMaze.rageid, tvdb=tvMaze.tvdbid, title=tvMaze.title)
        cacheEntry.save()
        return cacheEntry
    except IntegrityError as e:
        logger.debug("Unable to save cached TvMaze entry to database. Probably already exists")
        pass
    except Exception:
        logger.exception("Unable to save cached TvMaze entry to database")
        pass
Пример #4
0
    def testConvertTv(self):
        TvIdCache.delete().execute()
        id = infos.convertId("tvdb", "tvrage", "299350")
        self.assertEqual("47566", id)
        #This time from cache
        id = infos.convertId("tvdb", "tvrage", "299350")
        self.assertEqual("47566", id)

        TvIdCache.delete().execute()

        id = infos.convertId("tvdb", "tvmaze", "299350")
        self.assertEqual("3036", id)
        #This time from cache
        id = infos.convertId("tvdb", "tvmaze", "299350")
        self.assertEqual("3036", id)

        TvIdCache.delete().execute()
        id = infos.convertId("tvrage", "tvdb", "47566")
        self.assertEqual("299350", id)

        TvIdCache.delete().execute()
        id = infos.convertId("tvrage", "tvmaze", "47566")
        self.assertEqual("3036", id)

        TvIdCache.delete().execute()
        id = infos.convertId("tvmaze", "tvrage", "3036")
        self.assertEqual("47566", id)

        TvIdCache.delete().execute()
        id = infos.convertId("tvmaze", "tvdb", "3036")
        self.assertEqual("299350", id)
Пример #5
0
 def testGetTvTitleDoesntExist(self):
     TvIdCache.delete().execute()
     id = infos.convertId("tvdb", "title", "299350000")
     self.assertIsNone(id)
Пример #6
0
 def setUp(self):
     init_db("tests.db")
     TvIdCache().delete().execute()
Пример #7
0
    def testConvertTv(self):
        TvIdCache.delete().execute()
        id = infos.convertId("tvdb", "tvrage", "299350")
        self.assertEqual("47566", id)
        #This time from cache
        id = infos.convertId("tvdb", "tvrage", "299350")
        self.assertEqual("47566", id)
        
        TvIdCache.delete().execute()
        
        id = infos.convertId("tvdb", "tvmaze", "299350")
        self.assertEqual("3036", id)
        #This time from cache
        id = infos.convertId("tvdb", "tvmaze", "299350")
        self.assertEqual("3036", id)

        TvIdCache.delete().execute()
        id = infos.convertId("tvrage", "tvdb", "47566")
        self.assertEqual("299350", id)
        
        TvIdCache.delete().execute()
        id = infos.convertId("tvrage", "tvmaze", "47566")
        self.assertEqual("3036", id)
        
        TvIdCache.delete().execute()
        id = infos.convertId("tvmaze", "tvrage", "3036")
        self.assertEqual("47566", id)
        
        TvIdCache.delete().execute()
        id = infos.convertId("tvmaze", "tvdb", "3036")
        self.assertEqual("299350", id)
Пример #8
0
 def testGetTvTitleDoesntExist(self):
     TvIdCache.delete().execute()
     id = infos.convertId("tvdb", "title", "299350000")
     self.assertIsNone(id)
Пример #9
0
            iaa.save()
        except Exception as e:
            print(str(e))


def rndstr(n):
    return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(n))


database.db.init("c:\\temp\\playground.db")
database.db.connect()
database.Indexer.drop_table()
database.Indexer.create_table()
SearchResult.drop_table()
SearchResult.create_table()
TvIdCache.drop_table()
TvIdCache.create_table()


indexer1, created = database.Indexer.get_or_create(name="indexer1")
indexer2, created = database.Indexer.get_or_create(name="indexer2")
indexer3, created = database.Indexer.get_or_create(name="indexer3")
indexer4, created = database.Indexer.get_or_create(name="indexer4")
indexer5, created = database.Indexer.get_or_create(name="indexer5")
indexers = [indexer1, indexer2, indexer3, indexer4, indexer5]


now = time.time()
with database.db.atomic():
    # Prefil with 10000
    for x in range(1, 6):