]> git.phdru.name Git - bookmarks_db.git/commitdiff
Feat(Robots): Return HTTP status code
authorOleg Broytman <phd@phdru.name>
Wed, 31 Jul 2024 15:14:05 +0000 (18:14 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 31 Jul 2024 15:14:05 +0000 (18:14 +0300)
Robots/bkmk_robot_base.py
Robots/bkmk_rrequests.py
Robots/bkmk_rurllib2.py

index a03d5c1b16ec430ab17ac8f899655ae9cf9808bb..cc2574a00a8a9b31301203e3b17748f03d993bcf 100644 (file)
@@ -78,15 +78,15 @@ class robot_base(Robot):
             self.start = int(time.time())
             bookmark.icon = None
 
-            error, redirect_code, redirect_to, headers, content = \
+            error, http_status_code, redirect_to, headers, content = \
                 self.get(bookmark, bookmark.href, True)
 
             if error:
                 bookmark.error = error
                 return 1
 
-            if redirect_code:
-                self.set_redirect(bookmark, redirect_code, redirect_to)
+            if http_status_code and (http_status_code >= 300):
+                self.set_redirect(bookmark, http_status_code, redirect_to)
                 return 1
 
             size = 0
@@ -187,11 +187,15 @@ class robot_base(Robot):
                             try:
                                 _icon_url = icon_url
                                 for i in range(8):
-                                    error, icon_redirect_code, \
+                                    error, icon_status_code, \
                                         icon_redirect_to, icon_headers, \
                                         icon_data = \
                                         self.get(bookmark, _icon_url)
-                                    if icon_redirect_code:
+                                    if error:
+                                        raise IOError("No icon")
+                                        break
+                                    if icon_status_code and (
+                                            icon_status_code >= 300):
                                         _icon_url = icon_redirect_to
                                         self.log("   redirect to : %s"
                                                  % _icon_url)
index 5fe1ca10e5d34f9357aae3fae864d3c3c23fbb50..317c473a8750196564380a628f8d84721289b48d 100644 (file)
@@ -62,11 +62,11 @@ class robot_requests(robot_base):
                     if error is None:
                         self.proxy_ok.add(url_host)
         if error is not None:
-            if self.proxy and error != '404 not_found':
+            if self.proxy and r.status_code != 404:
                 self.log('   Proxy error    : %s' % error)
                 if url_host not in self.proxy_ok:
                     self.proxy_error.add(url_host)
-            return error, None, None, None, None
+            return error, r.status_code, None, None, None
         if r.is_redirect:
             return None, r.status_code, r.next.url, None, None
         return None, None, None, r.headers, r.content
index d1b679c11d68ebef2f14e815d3c2230cfd3c46d6..4b8927bfcf83a4fa2bb5c9e9a2b615ce8c9e8a88 100644 (file)
@@ -59,7 +59,7 @@ class robot_urllib2(robot_base):
             else:
                 self.log('   HTTP Error %s: %s' % (e.code, e.msg))
                 return ("HTTP Error %s: %s" % (e.code, e.msg),
-                        None, None, None, None)
+                        e.code, None, None, None)
 
         except urllib2.URLError as e:
             self.log('   URL Error: %s' % e.reason)