Repository: electricitymaps/electricitymaps-contrib

Issue:
Add Turkey
Check ENTSOE. Also, data seems to be available here: https://ytbs.teias.gov.tr/ytbs/frm_login.jsf
What needs to be done:
Copy this file (https://github.com/tmrowco/electricitymap/blob/master/parsers/example.py) and adapt it to the Turkish API.


Discussion:
Nothing on ENTSOE, but good data on the other site. 
I've had a quick look at this, and I'm happy to have a go this Sunday, or next week.

From what I can see the data is in the page itself, and this array here, in an array 24 objects long, one for each hour of the given date.

```json
{
    "biyokutle": "290.21",
    "asfaltitkomur": "264.95",
    "lng": "0",
    "barajli": "7018.11",
    "ithalkomur": "3136.01",
    "akarsu": "4831.78",
    "dogalgaz": "7117.30",
    "uluslarasi": "-258.00",
    "ruzgar": "1835.39",
    "saat": "1",
    "linyit": "3864.86",
    "fueloil": "162.30",
    "taskomur": "355.50",
    "nafta": "4.70",
    "jeotermal": "556.66"
  }, {
    "biyokutle": "276.88",
    "asfaltitkomur": "258.32",
    "lng": "0",
    "barajli": "6449.46",
    "ithalkomur": "2808.95",
    "akarsu": "4823.02",
    "dogalgaz": "6749.02",
    "uluslarasi": "-386.00",
    "ruzgar": "1714.24",
    "saat": "2",
    "linyit": "3847.23",
    "fueloil": "164.40",
    "taskomur": "361.50",
    "nafta": "4.70",
    "jeotermal": "559.12"
  }

```

The date for this info also appears to be here as well:

```html
<input id="formdash:bitisTarihi2_input"
name="formdash:bitisTarihi2_input"
type="text"
value="2017-04-21"
class="ui-inputfield ui-widget ui-state-default ui-corner-all"
placeholder="yil-ay-gun" />
```

I'm not sure what the keys mean yet, as I haven't had a go at trying to translate them - assuming they refer to the keys in the example, is there anything else I'd need to add to get this into the map?

Sounds cool. You need to write a script that can fetch those and map them into our datastructure.
Check out the example here: https://github.com/tmrowco/electricitymap/blob/master/parsers/example.py (just use the `fetch_production` method)

Resolving patch:
diff --git a/parsers/TR.py b/parsers/TR.py
new file mode 100644
--- /dev/null
+++ b/parsers/TR.py
@@ -0,0 +1,76 @@
+import requests
+import re
+import json
+import arrow
+
+SEARCH_DATA = re.compile(r'(?P<start>var data2=)(?P<data>{"yuk".*}]});')
+TIMEZONE = 'Europe/Istanbul'
+URL = 'https://ytbs.teias.gov.tr/ytbs/frm_login.jsf'
+EMPTY_DAY = -1
+
+MAP_GENERATION = {
+    'akarsu': 'hydro',
+    'barajli': 'hydro',
+    'dogalgaz': 'gas',
+    'jeotermal': 'geothermal',
+    'taskomur': 'coal',
+    'asfaltitkomur': 'coal',
+    'linyit': 'coal',
+    'ithalkomur': 'coal',
+    'ruzgar': 'wind',
+    'fueloil': 'oil',
+    'biyokutle': 'biomass',
+    'nafta': 'unknown'
+}
+
+
+def as_float(prod):
+    """Convert json values to float and sum all production for a further use"""
+    prod['total'] = 0.0
+    if isinstance(prod, dict) and 'yuk' not in prod.keys():
+        for prod_type, prod_val in prod.items():
+            prod[prod_type] = float(prod_val)
+            prod['total'] += prod[prod_type]
+    return prod
+
+
+def get_last_data_idx(productions):
+    """
+    Find index of the last production
+    :param productions: list of 24 production dict objects
+    :return: (int) index of the newest data or -1 if no data (empty day)
+    """
+    for i in range(len(productions)):
+        if productions[i]['total'] == 0:
+            return i - 1
+    return len(productions) - 1  # full day
+
+
+def fetch_production(country_code='TR', session=None):
+    r = session or requests.session()
+    tr_datetime = arrow.now(tz=TIMEZONE).datetime
+    data = {
+      'countryCode': country_code,
+      'production': {},
+      'storage': {},
+      'source': 'ytbs.teias.gov.tr',
+      'datetime': tr_datetime
+    }
+    response = r.get(URL)
+    str_data = re.search(SEARCH_DATA, response.text)
+    if str_data:
+        productions = json.loads(str_data.group('data'), object_hook=as_float)['yuk']
+        last_data_index = get_last_data_idx(productions)
+        if last_data_index != EMPTY_DAY:
+            last_prod = productions[last_data_index]
+            data['production'] = dict(zip(MAP_GENERATION.values(), [0] * len(MAP_GENERATION)))
+            for prod_type, prod_val in last_prod.items():
+                if prod_type in MAP_GENERATION.keys():
+                    data['production'][MAP_GENERATION[prod_type]] += prod_val
+            data['datetime'] = tr_datetime.replace(hour=last_data_index)
+    return data
+
+if __name__ == '__main__':
+    res = fetch_production()
+    print res
+    print sum(res['production'].values())


Test patch: