Deal with thingiverse returning no files for a thing. v0.8.3
authorOliver Matthews <oliver@codersoffortune.net>
Wed, 1 Jul 2020 08:52:05 +0000 (09:52 +0100)
committerOliver Matthews <oliver@codersoffortune.net>
Wed, 1 Jul 2020 08:52:05 +0000 (09:52 +0100)
README.md
thingy_grabber.py

index eec2397..ee37b71 100644 (file)
--- a/README.md
+++ b/README.md
@@ -85,6 +85,8 @@ python3, beautifulsoup4, requests, lxml
 - If there is an updated file, the old directory will be moved to `name_timestamp` where `timestamp` is the last upload time of the old files. The code will then copy unchanged files across and download any new ones.
 
 ## Changelog
+* v0.8.6
+  - Handle thingiverse returning no files for a thing gracefully.
 * v0.8.5
   - Strip '.'s from the end of filenames
   - If you fail a download for an already failed download it no longer throws an exception
index e9aeb06..02ea355 100755 (executable)
@@ -40,7 +40,7 @@ RETRY_COUNT = 3
 
 MAX_PATH_LENGTH = 250
 
-VERSION = "0.8.5"
+VERSION = "0.8.6"
 
 
 #BROWSER = webdriver.PhantomJS('./phantomjs')
@@ -333,6 +333,8 @@ class Thing:
 
         self.title = pc.title
         self._file_links=[]
+        if not pc.files:
+            logging.error("No files found for thing {} - probably thingiverse being broken, try again later".format(self.thing_id))
         for link in pc.files:
             logging.debug("Parsing link: {}".format(link.text))
             link_link = link.find_element_by_xpath(".//a").get_attribute("href")
@@ -431,6 +433,10 @@ class Thing:
             print("{} - {} already downloaded - skipping.".format(self.thing_id, self.title))
             return State.ALREADY_DOWNLOADED
 
+        if not self._file_links:
+            print("{} - {} appears to have no files. Thingiverse acting up again?".format(self.thing_id, self.title))
+            return State.FAILED
+
         # Have we already downloaded some things?
         timestamp_file = os.path.join(self.download_dir, 'timestamp.txt')
         prev_dir = None