]> git.phdru.name Git - bookmarks_db.git/commitdiff
Fear(robots): Try robots from a list
authorOleg Broytman <phd@phdru.name>
Wed, 31 Jul 2024 18:12:59 +0000 (21:12 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 31 Jul 2024 22:48:38 +0000 (01:48 +0300)
Default list is curl,requests,forking.

robots.py

index 70513f21717df13fde291be3a8ed484e4f93b11c..575f9bdf8c2cbe9319d4aae50350e1bb8c4495a8 100644 (file)
--- a/robots.py
+++ b/robots.py
@@ -15,7 +15,8 @@ import sys
 from os import environ
 from bkmk_objects import parse_params, set_params
 
-robot_name, robot_params = parse_params(environ.get("BKMK_ROBOT", "requests"))
+robot_names, robot_params = parse_params(
+    environ.get("BKMK_ROBOT", "curl,requests,forking"))
 
 
 def import_robot(robot_name):
@@ -27,5 +28,13 @@ def import_robot(robot_name):
     return ns['robot']
 
 
-robot = import_robot(robot_name)
-set_params(robot, robot_params)
+for robot_name in robot_names.split(','):
+    try:
+        robot = import_robot(robot_name)
+    except ImportError:
+        pass
+    else:
+        set_params(robot, robot_params)
+        break
+else:
+    raise ValueError("No robot found, tried " + robot_names)