prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [CVE] Download link to variable
  ## Description
  
  Set the download CVE link to variable, because otherwise the tool can hardly be used offline. Offline we can host the CVEs on a link that is not : "https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-"
  
  ## Reproducible Steps
  
  https://github.com/OpenCTI-Platform/connectors/blame/9d47ffdad1c2a7fbdd709565d5c3f670693b148f/cve/src/cve.py#L103
  
  ## Expected Output
  
  Url as a variable in the .yml
  
  ## Actual Output
  
  Permanent link : "https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-"
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `cve/src/cve.py`
  Content:
  ```
  1 # coding: utf-8
  2 
  3 import os
  4 import yaml
  5 import time
  6 import urllib.request
  7 import gzip
  8 import shutil
  9 
  10 from datetime import datetime
  11 from pycti import OpenCTIConnectorHelper, get_config_variable
  12 from cvetostix2 import convert
  13 
  14 
  15 class Cve:
  16     def __init__(self):
  17         # Instantiate the connector helper from config
  18         config_file_path = os.path.dirname(os.path.abspath(__file__)) + "/config.yml"
  19         config = (
  20             yaml.load(open(config_file_path), Loader=yaml.FullLoader)
  21             if os.path.isfile(config_file_path)
  22             else {}
  23         )
  24         self.helper = OpenCTIConnectorHelper(config)
  25         # Extra config
  26         self.cve_import_history = get_config_variable(
  27             "CVE_IMPORT_HISTORY", ["cve", "import_history"], config, False
  28         )
  29         self.cve_nvd_data_feed = get_config_variable(
  30             "CVE_NVD_DATA_FEED", ["cve", "nvd_data_feed"], config
  31         )
  32         self.cve_interval = get_config_variable(
  33             "CVE_INTERVAL", ["cve", "interval"], config, True
  34         )
  35         self.update_existing_data = get_config_variable(
  36             "CONNECTOR_UPDATE_EXISTING_DATA",
  37             ["connector", "update_existing_data"],
  38             config,
  39         )
  40 
  41     def get_interval(self):
  42         return int(self.cve_interval) * 60 * 60 * 24
  43 
  44     def convert_and_send(self, url):
  45         try:
  46             # Downloading json.gz file
  47             self.helper.log_info("Requesting the file " + url)
  48             urllib.request.urlretrieve(
  49                 self.cve_nvd_data_feed,
  50                 os.path.dirname(os.path.abspath(__file__)) + "/data.json.gz",
  51             )
  52             # Unzipping the file
  53             self.helper.log_info("Unzipping the file")
  54             with gzip.open("data.json.gz", "rb") as f_in:
  55                 with open("data.json", "wb") as f_out:
  56                     shutil.copyfileobj(f_in, f_out)
  57             # Converting the file to stix2
  58             self.helper.log_info("Converting the file")
  59             convert("data.json", "data-stix2.json")
  60             with open("data-stix2.json") as stix_json:
  61                 contents = stix_json.read()
  62                 self.helper.send_stix2_bundle(
  63                     contents, self.helper.connect_scope, self.update_existing_data
  64                 )
  65             # Remove files
  66             os.remove("data.json")
  67             os.remove("data.json.gz")
  68             os.remove("data-stix2.json")
  69         except Exception as e:
  70             self.helper.log_error(str(e))
  71             time.sleep(60)
  72 
  73     def run(self):
  74         self.helper.log_info("Fetching CVE knowledge...")
  75         while True:
  76             try:
  77                 # Get the current timestamp and check
  78                 timestamp = int(time.time())
  79                 current_state = self.helper.get_state()
  80                 if current_state is not None and "last_run" in current_state:
  81                     last_run = current_state["last_run"]
  82                     self.helper.log_info(
  83                         "Connector last run: "
  84                         + datetime.utcfromtimestamp(last_run).strftime(
  85                             "%Y-%m-%d %H:%M:%S"
  86                         )
  87                     )
  88                 else:
  89                     last_run = None
  90                     self.helper.log_info("Connector has never run")
  91                 # If the last_run is more than interval-1 day
  92                 if last_run is None or (
  93                     (timestamp - last_run)
  94                     > ((int(self.cve_interval) - 1) * 60 * 60 * 24)
  95                 ):
  96                     self.convert_and_send(self.cve_nvd_data_feed)
  97                     # If import history and never run
  98                     if last_run is None and self.cve_import_history:
  99                         now = datetime.now()
  100                         years = list(range(2002, now.year))
  101                         for year in years:
  102                             self.convert_and_send(
  103                                 "https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-"
  104                                 + str(year)
  105                                 + ".json.gz"
  106                             )
  107 
  108                     # Store the current timestamp as a last run
  109                     self.helper.log_info(
  110                         "Connector successfully run, storing last_run as "
  111                         + str(timestamp)
  112                     )
  113                     self.helper.set_state({"last_run": timestamp})
  114                     self.helper.log_info(
  115                         "Last_run stored, next run in: "
  116                         + str(round(self.get_interval() / 60 / 60 / 24, 2))
  117                         + " days"
  118                     )
  119                     time.sleep(60)
  120                 else:
  121                     new_interval = self.get_interval() - (timestamp - last_run)
  122                     self.helper.log_info(
  123                         "Connector will not run, next run in: "
  124                         + str(round(new_interval / 60 / 60 / 24, 2))
  125                         + " days"
  126                     )
  127                     time.sleep(60)
  128             except (KeyboardInterrupt, SystemExit):
  129                 self.helper.log_info("Connector stop")
  130                 exit(0)
  131             except Exception as e:
  132                 self.helper.log_error(str(e))
  133                 time.sleep(60)
  134 
  135 
  136 if __name__ == "__main__":
  137     try:
  138         cveConnector = Cve()
  139         cveConnector.run()
  140     except Exception as e:
  141         print(e)
  142         time.sleep(10)
  143         exit(0)
  144
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/cve/src/cve.py b/cve/src/cve.py
  --- a/cve/src/cve.py
  +++ b/cve/src/cve.py
  @@ -29,6 +29,9 @@
           self.cve_nvd_data_feed = get_config_variable(
               "CVE_NVD_DATA_FEED", ["cve", "nvd_data_feed"], config
           )
  +        self.cve_history_data_feed = get_config_variable(
  +            "CVE_HISTORY_DATA_FEED", ["cve", "history_data_feed"], config
  +        )
           self.cve_interval = get_config_variable(
               "CVE_INTERVAL", ["cve", "interval"], config, True
           )
  @@ -97,12 +100,10 @@
                       # If import history and never run
                       if last_run is None and self.cve_import_history:
                           now = datetime.now()
  -                        years = list(range(2002, now.year))
  +                        years = list(range(2002, now.year+1))
                           for year in years:
                               self.convert_and_send(
  -                                "https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-"
  -                                + str(year)
  -                                + ".json.gz"
  +                                f"{self.cve_history_data_feed}nvdcve-1.1-{year}.json.gz"
                               )
   
                       # Store the current timestamp as a last run
  
verification_info: {"golden_diff": "diff --git a/cve/src/cve.py b/cve/src/cve.py\n--- a/cve/src/cve.py\n+++ b/cve/src/cve.py\n@@ -29,6 +29,9 @@\n         self.cve_nvd_data_feed = get_config_variable(\n             \"CVE_NVD_DATA_FEED\", [\"cve\", \"nvd_data_feed\"], config\n         )\n+        self.cve_history_data_feed = get_config_variable(\n+            \"CVE_HISTORY_DATA_FEED\", [\"cve\", \"history_data_feed\"], config\n+        )\n         self.cve_interval = get_config_variable(\n             \"CVE_INTERVAL\", [\"cve\", \"interval\"], config, True\n         )\n@@ -97,12 +100,10 @@\n                     # If import history and never run\n                     if last_run is None and self.cve_import_history:\n                         now = datetime.now()\n-                        years = list(range(2002, now.year))\n+                        years = list(range(2002, now.year+1))\n                         for year in years:\n                             self.convert_and_send(\n-                                \"https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-\"\n-                                + str(year)\n-                                + \".json.gz\"\n+                                f\"{self.cve_history_data_feed}nvdcve-1.1-{year}.json.gz\"\n                             )\n \n                     # Store the current timestamp as a last run\n", "issue": "[CVE] Download link to variable\n## Description\r\n\r\nSet the download CVE link to variable, because otherwise the tool can hardly be used offline. Offline we can host the CVEs on a link that is not : \"https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-\"\r\n\r\n## Reproducible Steps\r\n\r\nhttps://github.com/OpenCTI-Platform/connectors/blame/9d47ffdad1c2a7fbdd709565d5c3f670693b148f/cve/src/cve.py#L103\r\n\r\n## Expected Output\r\n\r\nUrl as a variable in the .yml\r\n\r\n## Actual Output\r\n\r\nPermanent link : \"https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-\"\r\n\n", "before_files": [{"content": "# coding: utf-8\n\nimport os\nimport yaml\nimport time\nimport urllib.request\nimport gzip\nimport shutil\n\nfrom datetime import datetime\nfrom pycti import OpenCTIConnectorHelper, get_config_variable\nfrom cvetostix2 import convert\n\n\nclass Cve:\n    def __init__(self):\n        # Instantiate the connector helper from config\n        config_file_path = os.path.dirname(os.path.abspath(__file__)) + \"/config.yml\"\n        config = (\n            yaml.load(open(config_file_path), Loader=yaml.FullLoader)\n            if os.path.isfile(config_file_path)\n            else {}\n        )\n        self.helper = OpenCTIConnectorHelper(config)\n        # Extra config\n        self.cve_import_history = get_config_variable(\n            \"CVE_IMPORT_HISTORY\", [\"cve\", \"import_history\"], config, False\n        )\n        self.cve_nvd_data_feed = get_config_variable(\n            \"CVE_NVD_DATA_FEED\", [\"cve\", \"nvd_data_feed\"], config\n        )\n        self.cve_interval = get_config_variable(\n            \"CVE_INTERVAL\", [\"cve\", \"interval\"], config, True\n        )\n        self.update_existing_data = get_config_variable(\n            \"CONNECTOR_UPDATE_EXISTING_DATA\",\n            [\"connector\", \"update_existing_data\"],\n            config,\n        )\n\n    def get_interval(self):\n        return int(self.cve_interval) * 60 * 60 * 24\n\n    def convert_and_send(self, url):\n        try:\n            # Downloading json.gz file\n            self.helper.log_info(\"Requesting the file \" + url)\n            urllib.request.urlretrieve(\n                self.cve_nvd_data_feed,\n                os.path.dirname(os.path.abspath(__file__)) + \"/data.json.gz\",\n            )\n            # Unzipping the file\n            self.helper.log_info(\"Unzipping the file\")\n            with gzip.open(\"data.json.gz\", \"rb\") as f_in:\n                with open(\"data.json\", \"wb\") as f_out:\n                    shutil.copyfileobj(f_in, f_out)\n            # Converting the file to stix2\n            self.helper.log_info(\"Converting the file\")\n            convert(\"data.json\", \"data-stix2.json\")\n            with open(\"data-stix2.json\") as stix_json:\n                contents = stix_json.read()\n                self.helper.send_stix2_bundle(\n                    contents, self.helper.connect_scope, self.update_existing_data\n                )\n            # Remove files\n            os.remove(\"data.json\")\n            os.remove(\"data.json.gz\")\n            os.remove(\"data-stix2.json\")\n        except Exception as e:\n            self.helper.log_error(str(e))\n            time.sleep(60)\n\n    def run(self):\n        self.helper.log_info(\"Fetching CVE knowledge...\")\n        while True:\n            try:\n                # Get the current timestamp and check\n                timestamp = int(time.time())\n                current_state = self.helper.get_state()\n                if current_state is not None and \"last_run\" in current_state:\n                    last_run = current_state[\"last_run\"]\n                    self.helper.log_info(\n                        \"Connector last run: \"\n                        + datetime.utcfromtimestamp(last_run).strftime(\n                            \"%Y-%m-%d %H:%M:%S\"\n                        )\n                    )\n                else:\n                    last_run = None\n                    self.helper.log_info(\"Connector has never run\")\n                # If the last_run is more than interval-1 day\n                if last_run is None or (\n                    (timestamp - last_run)\n                    > ((int(self.cve_interval) - 1) * 60 * 60 * 24)\n                ):\n                    self.convert_and_send(self.cve_nvd_data_feed)\n                    # If import history and never run\n                    if last_run is None and self.cve_import_history:\n                        now = datetime.now()\n                        years = list(range(2002, now.year))\n                        for year in years:\n                            self.convert_and_send(\n                                \"https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-\"\n                                + str(year)\n                                + \".json.gz\"\n                            )\n\n                    # Store the current timestamp as a last run\n                    self.helper.log_info(\n                        \"Connector successfully run, storing last_run as \"\n                        + str(timestamp)\n                    )\n                    self.helper.set_state({\"last_run\": timestamp})\n                    self.helper.log_info(\n                        \"Last_run stored, next run in: \"\n                        + str(round(self.get_interval() / 60 / 60 / 24, 2))\n                        + \" days\"\n                    )\n                    time.sleep(60)\n                else:\n                    new_interval = self.get_interval() - (timestamp - last_run)\n                    self.helper.log_info(\n                        \"Connector will not run, next run in: \"\n                        + str(round(new_interval / 60 / 60 / 24, 2))\n                        + \" days\"\n                    )\n                    time.sleep(60)\n            except (KeyboardInterrupt, SystemExit):\n                self.helper.log_info(\"Connector stop\")\n                exit(0)\n            except Exception as e:\n                self.helper.log_error(str(e))\n                time.sleep(60)\n\n\nif __name__ == \"__main__\":\n    try:\n        cveConnector = Cve()\n        cveConnector.run()\n    except Exception as e:\n        print(e)\n        time.sleep(10)\n        exit(0)\n", "path": "cve/src/cve.py"}], "after_files": [{"content": "# coding: utf-8\n\nimport os\nimport yaml\nimport time\nimport urllib.request\nimport gzip\nimport shutil\n\nfrom datetime import datetime\nfrom pycti import OpenCTIConnectorHelper, get_config_variable\nfrom cvetostix2 import convert\n\n\nclass Cve:\n    def __init__(self):\n        # Instantiate the connector helper from config\n        config_file_path = os.path.dirname(os.path.abspath(__file__)) + \"/config.yml\"\n        config = (\n            yaml.load(open(config_file_path), Loader=yaml.FullLoader)\n            if os.path.isfile(config_file_path)\n            else {}\n        )\n        self.helper = OpenCTIConnectorHelper(config)\n        # Extra config\n        self.cve_import_history = get_config_variable(\n            \"CVE_IMPORT_HISTORY\", [\"cve\", \"import_history\"], config, False\n        )\n        self.cve_nvd_data_feed = get_config_variable(\n            \"CVE_NVD_DATA_FEED\", [\"cve\", \"nvd_data_feed\"], config\n        )\n        self.cve_history_data_feed = get_config_variable(\n            \"CVE_HISTORY_DATA_FEED\", [\"cve\", \"history_data_feed\"], config\n        )\n        self.cve_interval = get_config_variable(\n            \"CVE_INTERVAL\", [\"cve\", \"interval\"], config, True\n        )\n        self.update_existing_data = get_config_variable(\n            \"CONNECTOR_UPDATE_EXISTING_DATA\",\n            [\"connector\", \"update_existing_data\"],\n            config,\n        )\n\n    def get_interval(self):\n        return int(self.cve_interval) * 60 * 60 * 24\n\n    def convert_and_send(self, url):\n        try:\n            # Downloading json.gz file\n            self.helper.log_info(\"Requesting the file \" + url)\n            urllib.request.urlretrieve(\n                self.cve_nvd_data_feed,\n                os.path.dirname(os.path.abspath(__file__)) + \"/data.json.gz\",\n            )\n            # Unzipping the file\n            self.helper.log_info(\"Unzipping the file\")\n            with gzip.open(\"data.json.gz\", \"rb\") as f_in:\n                with open(\"data.json\", \"wb\") as f_out:\n                    shutil.copyfileobj(f_in, f_out)\n            # Converting the file to stix2\n            self.helper.log_info(\"Converting the file\")\n            convert(\"data.json\", \"data-stix2.json\")\n            with open(\"data-stix2.json\") as stix_json:\n                contents = stix_json.read()\n                self.helper.send_stix2_bundle(\n                    contents, self.helper.connect_scope, self.update_existing_data\n                )\n            # Remove files\n            os.remove(\"data.json\")\n            os.remove(\"data.json.gz\")\n            os.remove(\"data-stix2.json\")\n        except Exception as e:\n            self.helper.log_error(str(e))\n            time.sleep(60)\n\n    def run(self):\n        self.helper.log_info(\"Fetching CVE knowledge...\")\n        while True:\n            try:\n                # Get the current timestamp and check\n                timestamp = int(time.time())\n                current_state = self.helper.get_state()\n                if current_state is not None and \"last_run\" in current_state:\n                    last_run = current_state[\"last_run\"]\n                    self.helper.log_info(\n                        \"Connector last run: \"\n                        + datetime.utcfromtimestamp(last_run).strftime(\n                            \"%Y-%m-%d %H:%M:%S\"\n                        )\n                    )\n                else:\n                    last_run = None\n                    self.helper.log_info(\"Connector has never run\")\n                # If the last_run is more than interval-1 day\n                if last_run is None or (\n                    (timestamp - last_run)\n                    > ((int(self.cve_interval) - 1) * 60 * 60 * 24)\n                ):\n                    self.convert_and_send(self.cve_nvd_data_feed)\n                    # If import history and never run\n                    if last_run is None and self.cve_import_history:\n                        now = datetime.now()\n                        years = list(range(2002, now.year+1))\n                        for year in years:\n                            self.convert_and_send(\n                                f\"{self.cve_history_data_feed}nvdcve-1.1-{year}.json.gz\"\n                            )\n\n                    # Store the current timestamp as a last run\n                    self.helper.log_info(\n                        \"Connector successfully run, storing last_run as \"\n                        + str(timestamp)\n                    )\n                    self.helper.set_state({\"last_run\": timestamp})\n                    self.helper.log_info(\n                        \"Last_run stored, next run in: \"\n                        + str(round(self.get_interval() / 60 / 60 / 24, 2))\n                        + \" days\"\n                    )\n                    time.sleep(60)\n                else:\n                    new_interval = self.get_interval() - (timestamp - last_run)\n                    self.helper.log_info(\n                        \"Connector will not run, next run in: \"\n                        + str(round(new_interval / 60 / 60 / 24, 2))\n                        + \" days\"\n                    )\n                    time.sleep(60)\n            except (KeyboardInterrupt, SystemExit):\n                self.helper.log_info(\"Connector stop\")\n                exit(0)\n            except Exception as e:\n                self.helper.log_error(str(e))\n                time.sleep(60)\n\n\nif __name__ == \"__main__\":\n    try:\n        cveConnector = Cve()\n        cveConnector.run()\n    except Exception as e:\n        print(e)\n        time.sleep(10)\n        exit(0)\n", "path": "cve/src/cve.py"}]}