def create_plenum_protocol_parts(meeting,mks=None,mk_names=None):
    global _mks
    global _mk_names
    if mks is None or mk_names is None:
        (mks,mk_names)=get_all_mk_names()
    (_mks,_mk_names)=(mks,mk_names)
    global _parts
    _parts=[]
    txt=meeting.protocol_text.encode('utf-8')
    tree=ElementTree.fromstring(txt)
    titles=None
    for para in tree.iter('para'):
        (isBold,txt)=_plenum_parseParaElement(para)
        t=_plenum_parseParaText(txt,isBold)
        titles=_plenum_parsePara(txt,t,titles)
    for title in titles:
        titleHeader=title['t'].strip()
        titleBody=[]
        #_savePart(meeting,'',t,'title')
        for child in title['c']:
            if child['s']==1:
                # it's a speaker, save the aggregated title texts
                if len(titleHeader)>0 or len(titleBody)>0:
                    _savePart(meeting,titleHeader,'\n\n'.join(titleBody),'title')
                    titleHeader=''
                    titleBody=[]
                speakerHeader=child['t'].strip()
                speakerText=[]
                for schild in child['c']:
                    t=schild['t'].strip()
                    if len(t)>0:
                        speakerText.append(t)
                _savePart(meeting,speakerHeader,'\n\n'.join(speakerText),'speaker')
            else:
                t=child['t'].strip()
                if len(t)>0:
                    titleBody.append(t)
        if len(titleHeader)>0 or len(titleBody)>0:
            _savePart(meeting,titleHeader,'\n\n'.join(titleBody),'title')
    if len(_parts)>0:
        # find duplicates
        gotDuplicate=False
        otherMeetings=committees.models.CommitteeMeeting.objects.filter(date_string=meeting.date_string).exclude(id=meeting.id)
        if len(otherMeetings)>0:
            for otherMeeting in otherMeetings:
                if otherMeeting.parts.count()==len(_parts):
                    meeting.delete()
                    gotDuplicate=True
        if gotDuplicate:
            logger.debug('got a duplicate meeting - deleting my meeting')
        else:
            committees.models.ProtocolPart.objects.bulk_create(_parts)
            logger.debug('wrote '+str(len(_parts))+' protocol parts')
            for mk in _mks_attended:
                meeting.mks_attended.add(mk)
dataset/ETHPy150Open ofri/Open-Knesset/plenum/create_protocol_parts.py/create_plenum_protocol_parts/original