import csv
import os
import re
from collections import defaultdict
from datetime import date, timedelta, datetime
from glob import glob
from pprint import pprint
from typing import Union
from loguru import logger

from besser_tanken.data_loader import load_stations, load_prices_from, \
    load_prices
from besser_tanken.data_tools import group_prices


def _test_get_buehl_stations():
    for s in load_stations():
        if s['post_code'] in ['77815']:
            yield s


if __name__ == '__main__':
    buehl_station = next(_test_get_buehl_stations())
    print(buehl_station)
    for p in load_prices():
        # for p in load_prices_from(2021, 4, 1):
        print(p['date'])
        print(datetime.strptime(p['date'],
                                '%Y-%m-%d %H:%M:%S%z'))
    # exit()

    print(p)
    print(p['date'])
    # if ":" == p['date'][-3]:
    #    p['date'] = p['date'][:-3] + p['date'][-2:]
    #    print(p['date'])
    datetime_object = datetime.strptime(p['date'] + "00",
                                        '%Y-%m-%d %H:%M:%S%z')
    print(datetime_object)
    exit()
    prices = load_prices_from(2021, 4, 1)
    # print(prices)
    print(len(prices))
    prices = group_prices(prices)
    pprint(prices[buehl_station['uuid']])
