Repository: electricitymaps/electricitymaps-contrib

Issue:
Add price to Turkey
I am not sure which of the ticker [prices](https://www.epias.com.tr/en) to use but section 6.7.3 BLOCK ORDER BOOK in [this guide](https://www.epias.com.tr/wp-content/uploads/2017/06/INTRADAY_MARKET_USER_GUIDE_ENG_18.09.2017.pdf) may help.


Discussion:
What do the 3 ticker price headings translate to?
@jzlcdh I just scrolled down a little bit on that side and found this chart

![image](https://user-images.githubusercontent.com/25743609/38495869-9501d608-3bfb-11e8-95d8-dfd257d929f1.png)

which is using the "PTF" for the day-ahead market price.


The market operator also has a large Transparency platform 👍 
I could find a section for the day-ahead market, which is safer to use because you can set the desired date:

https://seffaflik.epias.com.tr/transparency/piyasalar/gop/ptf.xhtml

![image](https://user-images.githubusercontent.com/25743609/38496210-eb7f4e88-3bfc-11e8-9c2b-2a44ae205b04.png)

It seems from [the API conditions](https://www.epias.com.tr/wp-content/uploads/2018/02/EN_API_PORTAL_USER_MANUAL.pdf) that although it is free you have to be in a company to use it. As I am not part of a company this might be better assigned to someone else if it will be more convenient to use the API.
There is also the option to scrape the data from the html directly.
Sorry I haven't time to do this. How do I unassign myself from this issue?

Resolving patch:
diff --git a/parsers/TR.py b/parsers/TR.py
--- a/parsers/TR.py
+++ b/parsers/TR.py
@@ -4,12 +4,17 @@
 import re
 import json
 import arrow
+from bs4 import BeautifulSoup
+import datetime as dt
 
 SEARCH_DATA = re.compile(r'var gunlukUretimEgrisiData = (?P<data>.*);')
 TIMEZONE = 'Europe/Istanbul'
 URL = 'https://ytbs.teias.gov.tr/ytbs/frm_login.jsf'
 EMPTY_DAY = -1
 
+PRICE_URL = 'https://seffaflik.epias.com.tr/transparency/piyasalar/' \
+            'gop/ptf.xhtml'
+
 MAP_GENERATION = {
     'akarsu': 'hydro',
     'barajli': 'hydro',
@@ -54,6 +59,35 @@ def get_last_data_idx(productions):
     return len(productions) - 1  # full day
 
 
+def fetch_price():
+    soup = BeautifulSoup(requests.get(PRICE_URL).text, 'html.parser')
+    cells = soup.select('.TexAlCenter')
+
+    # data is in td elements with class "TexAlCenter" and role "gridcell"
+    data = list()
+    for cell in cells:
+        if cell.attrs.get('role', '') != 'gridcell':
+            continue
+        data.append(cell.text)
+
+    dates = [dt.datetime.strptime(val, '%d/%m/%Y').date()
+             for i, val in enumerate(data) if i % 3 == 0]
+    times = [dt.datetime.strptime(val, '%H:%M').time()
+             for i, val in enumerate(data) if i % 3 == 1]
+    prices = [float(val.replace(',', '.'))
+              for i, val in enumerate(data) if i % 3 == 2]
+
+    datapoints = [{
+        'zoneKey': 'TR',
+        'currency': 'TRY',
+        'datetime': arrow.get(
+            dt.datetime.combine(date, time)).to('Europe/Istanbul').datetime,
+        'price': price,
+        'source': 'epias.com.tr'
+    } for date, time, price in zip(dates, times, prices)]
+    return datapoints
+
+
 def fetch_production(zone_key='TR', session=None, target_datetime=None, logger=None):
     """
     Requests the last known production mix (in MW) of a given country
@@ -127,7 +161,10 @@ def fetch_production(zone_key='TR', session=None, target_datetime=None, logger=N
 
 
 if __name__ == '__main__':
-    """Main method, never used by the Electricity Map backend, but handy for testing."""
+    """Main method, never used by the Electricity Map backend, but handy for
+    testing."""
 
     print('fetch_production() ->')
     print(fetch_production())
+    print('fetch_price() ->')
+    print(fetch_price())


Test patch: