Exemple #1
0
 def test_filtering(self):
     mdi_list = [
         MetaDataItem(title="Vid1", url="c.com", download_src="youtube", id=1, collision_type="bike", location="China"),
         MetaDataItem(title="Vid2", url="c.com", download_src="youtube", id=2, collision_type="car", location="Canada"),
         MetaDataItem(title="Vid3", url="c.com", download_src="youtube", id=3, collision_type="bike", location="Canada"),
         MetaDataItem(title="Vid4", url="c.com", download_src="youtube", id=4, collision_type="car", location="China"),
         MetaDataItem(title="Vid5", url="c.com", download_src="youtube", id=5, collision_type="walking", location="Canada")
     ]
     
     fc1 = FilterCondition("location == 'Canada' and collision_type != 'car'")
     lst1 = fc1.filter(mdi_list)
     self.assertEqual(len(lst1), 2)
     self.assertEqual(lst1[0].id, 3)
     self.assertEqual(lst1[1].id, 5)
     
     fc2 = FilterCondition("title == 'Vid1' or title == 'Vid5'")
     lst2 = fc2.filter(mdi_list)
     self.assertEqual(len(lst2), 2)
     self.assertEqual(lst2[0].id, 1)
     self.assertEqual(lst2[1].id, 5)
    def fetch_newest_videos(
            self,
            last_id: str = None,
            filter_cond: FilterCondition = None) -> Iterator[MetaDataItem]:
        if last_id is not None:
            metadata_list = self.metadata_list[int(last_id):]
        else:
            metadata_list = self.metadata_list

        metadata_list = list(filter(None, metadata_list))
        if filter_cond is not None:
            return iter(filter_cond.filter(metadata_list))
        else:
            return iter(metadata_list)