# Buggy code
def fetch_GB():
    url = "http://www.bmreports.com/bsp/additional/soapfunctions.php?element=generationbyfueltypetable"

    response = requests.get(url)
    root = ET.fromstring(response.content)
    data = root[0]

    parsed = {}
    for item in data:
        parsed[item.get("TYPE")] = float(item.get("VAL"))

    obj = {
        "countryCode": COUNTRY_CODE,
        "datetime": arrow.get(data.get("AT")).datetime,  # Time given in UTC
    }
    obj["consumption"] = {}
    obj["production"] = {
        "coal": parsed["COAL"],
        "gas": parsed["CCGT"] + parsed["OCGT"],
        "nuclear": parsed["NUCLEAR"],
        "wind": parsed["WIND"],
        "oil": parsed["OIL"],
        "hydro": parsed["PS"] + parsed["NPSHYD"],
        "unknown": parsed["OTHER"],
    }
    obj["exchange"] = {
        "FR": parsed["INTFR"],
        "IE": parsed["INTIRL"],
        "NL": parsed["INTNED"],
    }
    total_production = 0
    for value in obj["production"].values():
        total_production += value
    obj["co2"] = (
        parsed["CCGT"] / total_production * 360
        + parsed["OCGT"] / total_production * 480
        + parsed["COAL"] / total_production * 910
        + parsed["OTHER"] / total_production * 300
        + parsed["OIL"] / total_production * 610
        + parsed["INTFR"] / total_production * 90
        + parsed["INTIRL"] / total_production * 450
        + parsed["INTNED"] / total_production * 550
        + parsed["INTEW"] / total_production * 450
    ) / 0.93

    return obj


# Traceback (IndexError)
Traceback (most recent call last):
File "feeder.py", line 51, in fetch_countries
obj = parser()
File "/home/parsers/PL.py", line 29, in fetch_PL
output_array = map(fetchValue, parameters)
File "/home/parsers/PL.py", line 21, in fetchValue
last = soup.find_all('point')[-1].find_all('quantity')[-1]
IndexError: list index out of range

# Fixed code
def fetch_GB(session=None):
    url = "http://www.bmreports.com/bsp/additional/soapfunctions.php?element=generationbyfueltypetable"

    response = (session or requests).get(url)
    root = ET.fromstring(response.content)
    data = root[0]

    parsed = {}
    for item in data:
        parsed[item.get("TYPE")] = float(item.get("VAL"))

    obj = {
        "countryCode": COUNTRY_CODE,
        "datetime": arrow.get(data.get("AT")).datetime,  # Time given in UTC
    }
    obj["consumption"] = {}
    obj["production"] = {
        "coal": parsed["COAL"],
        "gas": parsed["CCGT"] + parsed["OCGT"],
        "nuclear": parsed["NUCLEAR"],
        "wind": parsed["WIND"],
        "oil": parsed["OIL"],
        "hydro": parsed["PS"] + parsed["NPSHYD"],
        "unknown": parsed["OTHER"],
    }
    obj["exchange"] = {
        "FR": parsed["INTFR"],
        "IE": parsed["INTIRL"],
        "NL": parsed["INTNED"],
    }
    total_production = 0
    for value in obj["production"].values():
        total_production += value
    obj["co2"] = (
        parsed["CCGT"] / total_production * 360
        + parsed["OCGT"] / total_production * 480
        + parsed["COAL"] / total_production * 910
        + parsed["OTHER"] / total_production * 300
        + parsed["OIL"] / total_production * 610
        + parsed["INTFR"] / total_production * 90
        + parsed["INTIRL"] / total_production * 450
        + parsed["INTNED"] / total_production * 550
        + parsed["INTEW"] / total_production * 450
    ) / 0.93

    return obj