<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def read_templates(folder=None):
 """ Load yaml templates from template folder. Return list of dicts. Use built-in templates if no folder is set. Parameters folder : str user defined folder where they stores their files, if None uses built-in templates Returns ------- output : Instance of `InvoiceTemplate` template which match based on keywords Examples -------- InvoiceTemplate([('issuer', 'OYO'), ('fields', OrderedDict([('amount', 'GrandTotalRs(\\d+)'), ('date', 'Date:(\\d{1,2}\\/\\d{1,2}\\/\\d{1,4})'), ('invoice_number', '([A-Z0-9]+)CashatHotel')])), ('keywords', ['OYO', 'Oravel', 'Stays']), ('options', OrderedDict([('currency', 'INR'), ('decimal_separator', '.'), ('remove_whitespace', True)])), ('template_name', 'com.oyo.invoice.yml')]) After reading the template you can use the result as an instance of `InvoiceTemplate` to extract fields from `extract_data()` ('date', 'Date:(\\d{1,2}\\/\\d{1,2}\\/\\d{1,4})'), ('invoice_number', '([A-Z0-9]+)CashatHotel')])), ('keywords', ['OYO', 'Oravel', 'Stays']), ('options', OrderedDict([('currency', 'INR'), ('decimal_separator', '.'), ('remove_whitespace', True)])), ('template_name', 'com.oyo.invoice.yml')]) {'issuer': 'OYO', 'amount': 1939.0, 'date': datetime.datetime(2017, 12, 31, 0, 0), 'invoice_number': 'IBZY2087', 'currency': 'INR', 'desc': 'Invoice IBZY2087 from OYO'} """


    output = []

    if folder is None:
        folder = pkg_resources.resource_filename(__name__, 'templates')

    for path, subdirs, files in os.walk(folder):
        for name in sorted(files):
            if name.endswith('.yml'):
                with open(os.path.join(path, name), 'rb') as f:
                    encoding = chardet.detect(f.read())['encoding']
                with codecs.open(os.path.join(path, name), encoding=encoding) as template_file:
                    tpl = ordered_load(template_file.read())
                tpl['template_name'] = name

                # Test if all required fields are in template:
                assert 'keywords' in tpl.keys(), 'Missing keywords field.'

                # Keywords as list, if only one.
                if type(tpl['keywords']) is not list:
                    tpl['keywords'] = [tpl['keywords']]

                output.append(InvoiceTemplate(tpl))
    return output