Ejemplo n.º 1
0
    def test_save_stats(self):
        for stat in self.stats:
            db_stats, created = PDbManager.save_stats(stat)
            self.assertIsInstance(db_stats, PStats)
            self.assertTrue(created)

        db_stats, created = PDbManager.save_stats(self.stats[0])
        self.assertIsInstance(db_stats, PStats)
        self.assertFalse(created)
Ejemplo n.º 2
0
def torrents_stats_with_tracker(tracker: Tracker, category: list = None):
    nb_stats = 0
    with db_factory.get_instance():
        torrents = PDbManager.get_torrents_by_tracker(
            tracker,
            status=[Torrent._STATUS_NEW, Torrent._STATUS_FOLLOW],
            category=category)
        logger.debug("Torrents number: %s", len(torrents))

        stats_scraper = stats.StatsScraper(tracker)
        stats_scraper.torrents = torrents
        stats_scraper.run_by_batch()

        stats_collection = stats_scraper.stats_collection
        logger.debug("Stats number: %s", stats_collection.count())

        if stats_collection.count() != len(torrents):
            logger.warning("Statistics count is wrong %s/%s",
                           stats_collection.count(), len(torrents))

    with db_factory.get_instance():
        for tracker_stats in stats_collection.stats:
            _, created = PDbManager.save_stats(tracker_stats)
            nb_stats += created

    return nb_stats