# Nigerian Energy Data Bank – Power Plant Generation Scrape

**Source:** https://databank.energy.gov.ng/elect_production_view  
**Scraped:** 2026-06-18  
**Output files:**
- `NEFDB/datasets/grid_electricity/energy_databank_generation_by_plant.csv`
- `NEFDB/datasets/grid_electricity/energy_databank_generation_by_plant.json`

## What the portal exposes
The page is a Laravel/AdminLTE form with one drop-down for **Product Description** (power plant / metric) and two year selectors (**Year From**, **Year To**). Submitting the form does not reload the page; it triggers an XHR POST to:

```
POST https://databank.energy.gov.ng/elect_production_view/getResult
```

with the body:

```
_token=<csrf>&code=<PRODUCT_CODE>&year_from=<MIN_YEAR>&year_to=<MAX_YEAR>
```

The server returns JSON shaped like:

```json
{
  "data": [
    {"code": "ELPD_AFAM_VI", "description": "Afam VI Power Station IPP - Generation", "year": 2009, "value": 2208033, "unit": "MWh"}
  ]
}
```

Available years for each product are provided by a second endpoint:

```
GET https://databank.energy.gov.ng/elect_production_view/getYearFrom/<PRODUCT_CODE>
```

which returns a list of `{code, year}` objects. Both endpoints require the `X-Requested-With: XMLHttpRequest` header and the Laravel session cookies.

## Extraction method
1. Loaded the portal landing page with a Python `requests` session using a browser user-agent.
2. Parsed the HTML to extract the Laravel CSRF token (`input[name="_token"]`) and all `<option value="ELPD_...">` product codes.
3. For each code:
   - Called `getYearFrom/<code>` to discover the year range available for that series.
   - Called `getResult` with `_token`, `code`, `year_from` and `year_to` set to the observed min/max years.
   - Parsed the JSON and appended the records.
4. Wrote the combined records to CSV and JSON.
5. Retried each HTTP call up to 3 times with exponential backoff and used 90 s timeouts.

## Coverage captured
- **30 product series** covering 12 power plants / stations.
- **653 data rows** in total.
- Series include **Generation** (MWh or MW), **Gas Used/Utilized** (Cubic Meter), and hydro **Water Used / Reservoir Inflow / Outflow**.
- Year ranges vary by plant; the oldest data is for Kainji (1971–)
 and the newest is 2020 for the NIPP/IPP plants.

## Limitations and caveats
- The portal only exposes **annual** values through this endpoint; no monthly or daily resolution was found.
- Some series use **MW** as the unit while most generation series use **MWh**; values should be interpreted with their stated unit.
- Only the publicly visible drop-down series were extracted; log-in-gated datasets may exist.
- A small number of assets (CSS/JS map files) returned HTTP 503, but they were not required for data extraction.
- The portal was stable during the run; no CAPTCHA or blocking was encountered.
