| 45 | return f"A scraper with the name '{scraper_name}' does not exist. The scraper_name must be {valid_names_string}." if len(valid_scraper_names) == 1 else f"A scraper with the name '{scraper_name}' does not exist. The scraper_name must be one of {valid_names_string}." |
| 46 | |
| 47 | class _Server: |
| 48 | def __init__(self): |
| 49 | self.scrapers = {} |
| 50 | self.rate_limit = {"browser": 1, "request": 30, "task": 30} |
| 51 | self.controls_cache = {} # Cache to store Controls instances |
| 52 | self.cache = False |
| 53 | self.config = None |
| 54 | self.database_url = None |
| 55 | self.database_options = None |
| 56 | self._is_database_initialized = False |
| 57 | |
| 58 | def set_database_url(self, database_url=None, database_options=None): |
| 59 | if self._is_database_initialized: |
| 60 | raise Exception('The database has already been initialized. To resolve this error, ensure that the line ("from botasaurus_server.run import run") comes after the line ("import backend.scrapers") in the "run.py" file.') |
| 61 | self.database_url = database_url |
| 62 | self.database_options = database_options |
| 63 | |
| 64 | |
| 65 | def get_config(self): |
| 66 | if not self.config: |
| 67 | self.config = { |
| 68 | "title": "Botasaurus", |
| 69 | "header_title": "Botasaurus", |
| 70 | "description": "Build Awesome Scrapers with Botasaurus, The All in One Scraping Framework.", |
| 71 | "right_header": { |
| 72 | "text": "Love It? Star It! ★", |
| 73 | "link": "https://github.com/omkarcloud/botasaurus", |
| 74 | }, |
| 75 | "readme": get_readme(), |
| 76 | } |
| 77 | return self.config |
| 78 | |
| 79 | def configure( |
| 80 | self, |
| 81 | title="", |
| 82 | header_title="", |
| 83 | description="", |
| 84 | right_header={"text": "", "link": ""}, |
| 85 | readme="", |
| 86 | ): |
| 87 | """ |
| 88 | Creates a configuration dictionary for scraper. |
| 89 | |
| 90 | :param header_title (str, optional): The title to be displayed in the header section of the page. |
| 91 | :param description (str, optional): A brief description of the Scraper. |
| 92 | :param right_header (dict, optional): A dictionary containing optional text and an optional link for the right-side header. |
| 93 | :raises ValueError: If right_header is not a dictionary or contains invalid keys. |
| 94 | |
| 95 | :return: dict: A dictionary containing the scraper's configuration. |
| 96 | """ |
| 97 | |
| 98 | if not isinstance(right_header, dict): |
| 99 | raise ValueError("right_header must be a dictionary") |
| 100 | |
| 101 | valid_keys = {"text", "link"} |
| 102 | if not all(key in valid_keys for key in right_header): |
| 103 | raise ValueError("right_header can only contain 'text' and 'link' keys") |
| 104 | |