prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  First try at building a parser using data from Quebec
  Hopefully this will show up on the map somehow.  I look forward to seeing what changes will be made in order to make this parser functional.  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `parsers/CA_QC.py`
  Content:
  ```
  1 import requests
  2 import logging
  3 from pprint import pprint
  4 # The arrow library is used to handle datetimes
  5 import arrow
  6 
  7 PRODUCTION_URL = "https://www.hydroquebec.com/data/documents-donnees/donnees-ouvertes/json/production.json"
  8 CONSUMPTION_URL = "https://www.hydroquebec.com/data/documents-donnees/donnees-ouvertes/json/demande.json"
  9 # Reluctant to call it 'timezone', since we are importing 'timezone' from datetime
  10 timezone_id = 'America/Montreal'
  11 
  12 def fetch_production(
  13     zone_key="CA-QC",
  14     session=None,
  15     target_datetime=None,
  16     logger=logging.getLogger(__name__),
  17 ) -> dict:
  18     """Requests the last known production mix (in MW) of a given region.
  19        In this particular case, translated mapping of JSON keys are also required"""
  20 
  21     def if_exists(elem: dict, etype: str):
  22 
  23         english = {
  24             "hydraulique": "hydro",
  25             "thermique": "thermal",
  26             "solaire": "solar",
  27             "eolien": "wind",
  28             "autres": "unknown",
  29             "valeurs": "values",
  30         }
  31         english = {v: k for k, v in english.items()}
  32         try:
  33             return elem["valeurs"][english[etype]]
  34         except KeyError:
  35             return 0.0
  36 
  37     data = _fetch_quebec_production()
  38     for elem in reversed(data["details"]):
  39         if elem["valeurs"]["total"] != 0:
  40 
  41             return {
  42                 "zoneKey": zone_key,
  43                 "datetime":  arrow.get(elem["date"], tzinfo=timezone_id).datetime,
  44                 "production": {
  45                     "biomass": 0.0,
  46                     "coal": 0.0,
  47 
  48                     # per https://github.com/tmrowco/electricitymap-contrib/issues/3218 , thermal generation
  49                     # is at Bécancour gas turbine. It is reported with a delay, and data source returning 0.0
  50                     # can indicate either no generation or not-yet-reported generation.
  51                     # To handle this, if reported value is 0.0, overwrite it to None, so that backend can know
  52                     # this is not entirely reliable and might be updated later.
  53                     "gas": if_exists(elem, "thermal") or None,
  54 
  55                     "hydro": if_exists(elem, "hydro"),
  56                     "nuclear": 0.0,
  57                     "oil": 0.0,
  58                     "solar": if_exists(elem, "solar"),
  59                     "wind": if_exists(elem, "wind"),
  60                     "geothermal": 0.0,
  61                     "unknown": if_exists(elem, "unknown"),
  62                 },
  63                 "source": "hydroquebec.com",
  64             }
  65 
  66 
  67 def fetch_consumption(zone_key="CA-QC", session=None, target_datetime=None, logger=None):
  68     data = _fetch_quebec_consumption()
  69     for elem in reversed(data["details"]):
  70         if "demandeTotal" in elem["valeurs"]:
  71             return {
  72                 "zoneKey": zone_key,
  73                 "datetime": arrow.get(elem["date"], tzinfo=timezone_id).datetime,
  74                 "consumption": elem["valeurs"]["demandeTotal"],
  75                 "source": "hydroquebec.com",
  76             }
  77 
  78 
  79 def _fetch_quebec_production(logger=logging.getLogger(__name__)) -> str:
  80     response = requests.get(PRODUCTION_URL)
  81 
  82     if not response.ok:
  83         logger.info('CA-QC: failed getting requested production data from hydroquebec - URL {}'.format(PRODUCTION_URL))
  84     return response.json()
  85 
  86 
  87 def _fetch_quebec_consumption(logger=logging.getLogger(__name__)) -> str:
  88     response = requests.get(CONSUMPTION_URL)
  89 
  90     if not response.ok:
  91         logger.info('CA-QC: failed getting requested consumption data from hydroquebec - URL {}'.format(CONSUMPTION_URL))
  92     return response.json()
  93 
  94 
  95 if __name__ == '__main__':
  96     """Main method, never used by the Electricity Map backend, but handy for testing."""
  97 
  98     test_logger = logging.getLogger()
  99 
  100     print('fetch_production() ->')
  101     pprint(fetch_production(logger=test_logger))
  102 
  103     print('fetch_consumption() ->')
  104     pprint(fetch_consumption(logger=test_logger))
  105
  ```
  --- 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/parsers/CA_QC.py b/parsers/CA_QC.py
  --- a/parsers/CA_QC.py
  +++ b/parsers/CA_QC.py
  @@ -25,8 +25,9 @@
               "thermique": "thermal",
               "solaire": "solar",
               "eolien": "wind",
  -            "autres": "unknown",
  -            "valeurs": "values",
  +            # autres is all renewable, and mostly biomass.  See Github    #3218
  +            "autres": "biomass",
  +            "valeurs": "values"
           }
           english = {v: k for k, v in english.items()}
           try:
  @@ -42,21 +43,18 @@
                   "zoneKey": zone_key,
                   "datetime":  arrow.get(elem["date"], tzinfo=timezone_id).datetime,
                   "production": {
  -                    "biomass": 0.0,
  +                    "biomass": if_exists(elem, "biomass"),
                       "coal": 0.0,
  -
  -                    # per https://github.com/tmrowco/electricitymap-contrib/issues/3218 , thermal generation
  -                    # is at Bécancour gas turbine. It is reported with a delay, and data source returning 0.0
  -                    # can indicate either no generation or not-yet-reported generation.
  -                    # To handle this, if reported value is 0.0, overwrite it to None, so that backend can know
  -                    # this is not entirely reliable and might be updated later.
  -                    "gas": if_exists(elem, "thermal") or None,
  -
                       "hydro": if_exists(elem, "hydro"),
                       "nuclear": 0.0,
                       "oil": 0.0,
                       "solar": if_exists(elem, "solar"),
                       "wind": if_exists(elem, "wind"),
  +                    # See Github issue #3218, Québec's thermal generation is at Bécancour gas turbine.
  +                    # It is reported with a delay, and data source returning 0.0 can indicate either no generation or not-yet-reported generation.
  +                    # Thus, if value is 0.0, overwrite it to None, so that backend can know this is not entirely reliable and might be updated later.
  +                    "gas": if_exists(elem, "thermal") or None,
  +                    # There are no geothermal electricity generation stations in Québec (and all of Canada for that matter).
                       "geothermal": 0.0,
                       "unknown": if_exists(elem, "unknown"),
                   },
  
verification_info: {"golden_diff": "diff --git a/parsers/CA_QC.py b/parsers/CA_QC.py\n--- a/parsers/CA_QC.py\n+++ b/parsers/CA_QC.py\n@@ -25,8 +25,9 @@\n             \"thermique\": \"thermal\",\n             \"solaire\": \"solar\",\n             \"eolien\": \"wind\",\n-            \"autres\": \"unknown\",\n-            \"valeurs\": \"values\",\n+            # autres is all renewable, and mostly biomass.  See Github    #3218\n+            \"autres\": \"biomass\",\n+            \"valeurs\": \"values\"\n         }\n         english = {v: k for k, v in english.items()}\n         try:\n@@ -42,21 +43,18 @@\n                 \"zoneKey\": zone_key,\n                 \"datetime\":  arrow.get(elem[\"date\"], tzinfo=timezone_id).datetime,\n                 \"production\": {\n-                    \"biomass\": 0.0,\n+                    \"biomass\": if_exists(elem, \"biomass\"),\n                     \"coal\": 0.0,\n-\n-                    # per https://github.com/tmrowco/electricitymap-contrib/issues/3218 , thermal generation\n-                    # is at B\u00e9cancour gas turbine. It is reported with a delay, and data source returning 0.0\n-                    # can indicate either no generation or not-yet-reported generation.\n-                    # To handle this, if reported value is 0.0, overwrite it to None, so that backend can know\n-                    # this is not entirely reliable and might be updated later.\n-                    \"gas\": if_exists(elem, \"thermal\") or None,\n-\n                     \"hydro\": if_exists(elem, \"hydro\"),\n                     \"nuclear\": 0.0,\n                     \"oil\": 0.0,\n                     \"solar\": if_exists(elem, \"solar\"),\n                     \"wind\": if_exists(elem, \"wind\"),\n+                    # See Github issue #3218, Qu\u00e9bec's thermal generation is at B\u00e9cancour gas turbine.\n+                    # It is reported with a delay, and data source returning 0.0 can indicate either no generation or not-yet-reported generation.\n+                    # Thus, if value is 0.0, overwrite it to None, so that backend can know this is not entirely reliable and might be updated later.\n+                    \"gas\": if_exists(elem, \"thermal\") or None,\n+                    # There are no geothermal electricity generation stations in Qu\u00e9bec (and all of Canada for that matter).\n                     \"geothermal\": 0.0,\n                     \"unknown\": if_exists(elem, \"unknown\"),\n                 },\n", "issue": "First try at building a parser using data from Quebec\nHopefully this will show up on the map somehow.  I look forward to seeing what changes will be made in order to make this parser functional.  \n", "before_files": [{"content": "import requests\nimport logging\nfrom pprint import pprint\n# The arrow library is used to handle datetimes\nimport arrow\n\nPRODUCTION_URL = \"https://www.hydroquebec.com/data/documents-donnees/donnees-ouvertes/json/production.json\"\nCONSUMPTION_URL = \"https://www.hydroquebec.com/data/documents-donnees/donnees-ouvertes/json/demande.json\"\n# Reluctant to call it 'timezone', since we are importing 'timezone' from datetime\ntimezone_id = 'America/Montreal'\n\ndef fetch_production(\n    zone_key=\"CA-QC\",\n    session=None,\n    target_datetime=None,\n    logger=logging.getLogger(__name__),\n) -> dict:\n    \"\"\"Requests the last known production mix (in MW) of a given region.\n       In this particular case, translated mapping of JSON keys are also required\"\"\"\n\n    def if_exists(elem: dict, etype: str):\n\n        english = {\n            \"hydraulique\": \"hydro\",\n            \"thermique\": \"thermal\",\n            \"solaire\": \"solar\",\n            \"eolien\": \"wind\",\n            \"autres\": \"unknown\",\n            \"valeurs\": \"values\",\n        }\n        english = {v: k for k, v in english.items()}\n        try:\n            return elem[\"valeurs\"][english[etype]]\n        except KeyError:\n            return 0.0\n\n    data = _fetch_quebec_production()\n    for elem in reversed(data[\"details\"]):\n        if elem[\"valeurs\"][\"total\"] != 0:\n\n            return {\n                \"zoneKey\": zone_key,\n                \"datetime\":  arrow.get(elem[\"date\"], tzinfo=timezone_id).datetime,\n                \"production\": {\n                    \"biomass\": 0.0,\n                    \"coal\": 0.0,\n\n                    # per https://github.com/tmrowco/electricitymap-contrib/issues/3218 , thermal generation\n                    # is at B\u00e9cancour gas turbine. It is reported with a delay, and data source returning 0.0\n                    # can indicate either no generation or not-yet-reported generation.\n                    # To handle this, if reported value is 0.0, overwrite it to None, so that backend can know\n                    # this is not entirely reliable and might be updated later.\n                    \"gas\": if_exists(elem, \"thermal\") or None,\n\n                    \"hydro\": if_exists(elem, \"hydro\"),\n                    \"nuclear\": 0.0,\n                    \"oil\": 0.0,\n                    \"solar\": if_exists(elem, \"solar\"),\n                    \"wind\": if_exists(elem, \"wind\"),\n                    \"geothermal\": 0.0,\n                    \"unknown\": if_exists(elem, \"unknown\"),\n                },\n                \"source\": \"hydroquebec.com\",\n            }\n\n\ndef fetch_consumption(zone_key=\"CA-QC\", session=None, target_datetime=None, logger=None):\n    data = _fetch_quebec_consumption()\n    for elem in reversed(data[\"details\"]):\n        if \"demandeTotal\" in elem[\"valeurs\"]:\n            return {\n                \"zoneKey\": zone_key,\n                \"datetime\": arrow.get(elem[\"date\"], tzinfo=timezone_id).datetime,\n                \"consumption\": elem[\"valeurs\"][\"demandeTotal\"],\n                \"source\": \"hydroquebec.com\",\n            }\n\n\ndef _fetch_quebec_production(logger=logging.getLogger(__name__)) -> str:\n    response = requests.get(PRODUCTION_URL)\n\n    if not response.ok:\n        logger.info('CA-QC: failed getting requested production data from hydroquebec - URL {}'.format(PRODUCTION_URL))\n    return response.json()\n\n\ndef _fetch_quebec_consumption(logger=logging.getLogger(__name__)) -> str:\n    response = requests.get(CONSUMPTION_URL)\n\n    if not response.ok:\n        logger.info('CA-QC: failed getting requested consumption data from hydroquebec - URL {}'.format(CONSUMPTION_URL))\n    return response.json()\n\n\nif __name__ == '__main__':\n    \"\"\"Main method, never used by the Electricity Map backend, but handy for testing.\"\"\"\n\n    test_logger = logging.getLogger()\n\n    print('fetch_production() ->')\n    pprint(fetch_production(logger=test_logger))\n\n    print('fetch_consumption() ->')\n    pprint(fetch_consumption(logger=test_logger))\n", "path": "parsers/CA_QC.py"}], "after_files": [{"content": "import requests\nimport logging\nfrom pprint import pprint\n# The arrow library is used to handle datetimes\nimport arrow\n\nPRODUCTION_URL = \"https://www.hydroquebec.com/data/documents-donnees/donnees-ouvertes/json/production.json\"\nCONSUMPTION_URL = \"https://www.hydroquebec.com/data/documents-donnees/donnees-ouvertes/json/demande.json\"\n# Reluctant to call it 'timezone', since we are importing 'timezone' from datetime\ntimezone_id = 'America/Montreal'\n\ndef fetch_production(\n    zone_key=\"CA-QC\",\n    session=None,\n    target_datetime=None,\n    logger=logging.getLogger(__name__),\n) -> dict:\n    \"\"\"Requests the last known production mix (in MW) of a given region.\n       In this particular case, translated mapping of JSON keys are also required\"\"\"\n\n    def if_exists(elem: dict, etype: str):\n\n        english = {\n            \"hydraulique\": \"hydro\",\n            \"thermique\": \"thermal\",\n            \"solaire\": \"solar\",\n            \"eolien\": \"wind\",\n            # autres is all renewable, and mostly biomass.  See Github    #3218\n            \"autres\": \"biomass\",\n            \"valeurs\": \"values\"\n        }\n        english = {v: k for k, v in english.items()}\n        try:\n            return elem[\"valeurs\"][english[etype]]\n        except KeyError:\n            return 0.0\n\n    data = _fetch_quebec_production()\n    for elem in reversed(data[\"details\"]):\n        if elem[\"valeurs\"][\"total\"] != 0:\n\n            return {\n                \"zoneKey\": zone_key,\n                \"datetime\":  arrow.get(elem[\"date\"], tzinfo=timezone_id).datetime,\n                \"production\": {\n                    \"biomass\": if_exists(elem, \"biomass\"),\n                    \"coal\": 0.0,\n                    \"hydro\": if_exists(elem, \"hydro\"),\n                    \"nuclear\": 0.0,\n                    \"oil\": 0.0,\n                    \"solar\": if_exists(elem, \"solar\"),\n                    \"wind\": if_exists(elem, \"wind\"),\n                    # See Github issue #3218, Qu\u00e9bec's thermal generation is at B\u00e9cancour gas turbine.\n                    # It is reported with a delay, and data source returning 0.0 can indicate either no generation or not-yet-reported generation.\n                    # Thus, if value is 0.0, overwrite it to None, so that backend can know this is not entirely reliable and might be updated later.\n                    \"gas\": if_exists(elem, \"thermal\") or None,\n                    # There are no geothermal electricity generation stations in Qu\u00e9bec (and all of Canada for that matter).\n                    \"geothermal\": 0.0,\n                    \"unknown\": if_exists(elem, \"unknown\"),\n                },\n                \"source\": \"hydroquebec.com\",\n            }\n\n\ndef fetch_consumption(zone_key=\"CA-QC\", session=None, target_datetime=None, logger=None):\n    data = _fetch_quebec_consumption()\n    for elem in reversed(data[\"details\"]):\n        if \"demandeTotal\" in elem[\"valeurs\"]:\n            return {\n                \"zoneKey\": zone_key,\n                \"datetime\": arrow.get(elem[\"date\"], tzinfo=timezone_id).datetime,\n                \"consumption\": elem[\"valeurs\"][\"demandeTotal\"],\n                \"source\": \"hydroquebec.com\",\n            }\n\n\ndef _fetch_quebec_production(logger=logging.getLogger(__name__)) -> str:\n    response = requests.get(PRODUCTION_URL)\n\n    if not response.ok:\n        logger.info('CA-QC: failed getting requested production data from hydroquebec - URL {}'.format(PRODUCTION_URL))\n    return response.json()\n\n\ndef _fetch_quebec_consumption(logger=logging.getLogger(__name__)) -> str:\n    response = requests.get(CONSUMPTION_URL)\n\n    if not response.ok:\n        logger.info('CA-QC: failed getting requested consumption data from hydroquebec - URL {}'.format(CONSUMPTION_URL))\n    return response.json()\n\n\nif __name__ == '__main__':\n    \"\"\"Main method, never used by the Electricity Map backend, but handy for testing.\"\"\"\n\n    test_logger = logging.getLogger()\n\n    print('fetch_production() ->')\n    pprint(fetch_production(logger=test_logger))\n\n    print('fetch_consumption() ->')\n    pprint(fetch_consumption(logger=test_logger))\n", "path": "parsers/CA_QC.py"}]}