<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_pa11y_results(item, pa11y_results, data_dir):
 """ Write the output from pa11y into a data file. """

    data = dict(item)
    data['pa11y'] = pa11y_results

    # it would be nice to use the URL as the filename,
    # but that gets complicated (long URLs, special characters, etc)
    # so we'll make the filename a hash of the URL instead,
    # and throw in the access time so that we can store the same URL
    # multiple times in this data directory
    hasher = hashlib.md5()
    hasher.update(item["url"].encode('utf8'))
    hasher.update(item["accessed_at"].isoformat().encode('utf8'))
    basename = hasher.hexdigest()
    filename = basename + ".json"
    filepath = data_dir / filename
    data_dir.makedirs_p()
    text = json.dumps(data, cls=DateTimeEncoder)
    filepath.write_text(text)