<commit_before>import os
import xml.etree.ElementTree as ET


DATAFILE = os.path.join(os.path.dirname(__file__), 'blocklist.xml')
URL = '{http://www.mozilla.org/2006/addons-blocklist}'
tree = ET.parse(DATAFILE)
root = tree.getroot()

certs = []

for item in root.iterfind('%scertItems/*' % URL):
    cert = {'issuerName': item.get('issuerName'),
            'serialNumber': item.get('serialNumber')}

    certs.append(cert)

print certs
<commit_msg>filing Kinto with the items<commit_after>import os
import hashlib
import uuid

import xml.etree.ElementTree as ET
from kinto_client import Bucket
from kinto_client.exceptions import KintoException


def create_id(cert):
    # XXX will do better later
    hash = hashlib.md5()
    for value in cert.values():
        hash.update(str(value))
    return str(uuid.UUID(hash.hexdigest()))


DATAFILE = os.path.join(os.path.dirname(__file__), 'blocklist.xml')
URL = '{http://www.mozilla.org/2006/addons-blocklist}'
tree = ET.parse(DATAFILE)
root = tree.getroot()

bucket = Bucket('default', server_url='http://localhost:8888/v1',
                auth=('tarek', 'p4ssw0rd'))

crl_collection = bucket.get_collection('onecrl')


for item in root.iterfind('%scertItems/*' % URL):
    cert = {}
    for key in ('subject', 'publicKeyHash', 'serialNumber', 'issuerName'):
        cert[key] = item.get(key)

    cert['id'] = create_id(cert)

    # can I save it at once and do a single query to kinto?
    try:
        record = crl_collection.create_record(cert)
        record.save()
    except KintoException as e:
        raise Exception(e.response.content)
{'fraction_non_alphanumeric': 0.14043887147335424, 'fraction_numerical': 0.010031347962382446, 'mean_word_length': 3.7927927927927927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1828906', 'n_tokens_mistral': 549, 'n_tokens_neox': 530, 'n_words': 123}