def test_pinterest(): collect = CollectLinks(no_gui=True, no_driver=False) with patch("collect_links.CollectLinks.browser", create=True, new_callable=PropertyMock, return_value=Chrome()): result = collect.pinterest("test", "Berlin") assert result == ["http://www.test.com"]
def download_from_site(self, keyword, region, site_code): site_name = Sites.get_text(site_code) add_url = Sites.get_face_url(site_code) if self.face else "" try: collect = CollectLinks( no_gui=self.no_gui, no_driver=self.no_driver) # initialize chrome driver except Exception as e: print("Error occurred while initializing chromedriver - {}".format( e)) return try: print("Collecting links... {} from {}".format(keyword, site_name)) if site_code == Sites.GOOGLE: links = collect.google(keyword, region, add_url) elif site_code == Sites.GOOGLE_FULL: links = collect.google_full(keyword, region, add_url, self.limit) else: print("Invalid Site Code") links = [] print("Google Links:", len(links)) links = links + collect.pinterest(keyword, region, add_url, self.limit) print("Total Links:", len(links)) print("Downloading images from {} collected links... {} from {}". format(len(links), keyword, site_name)) self.download_images(keyword, links, site_name, max_count=len(links)) print("Done {} : {}".format(site_name, keyword)) except Exception as e: print("Exception {}:{} - {}".format(site_name, keyword, e))