+def add_fundraising(doc, fundraising):
+ # Before each naglowek_rozdzial and naglowek_scena and in the end
+ spots = []
+ for naglowek in doc.xpath('//naglowek_czesc|//naglowek_akt'):
+ spot = etree.Element('f_spot')
+ naglowek.addprevious(spot)
+ spots.append(spot)
+ spot = etree.Element('f_spot')
+ doc.getroot()[-1][-1].append(spot)
+ spots.append(spot)
+ e = len(spots)
+ nfunds = len(fundraising)
+ if e > 4 * nfunds:
+ nfunds *= 2
+ for f in range(nfunds):
+ spot_index = int(f / nfunds * e)
+ spots[spot_index].set('active', 'true')
+ elem = etree.fromstring('<f_spot>' + fundraising[f % len(fundraising)] + '</f_spot>')
+ spots[spot_index].text = elem.text
+ for c in elem:
+ spots[spot_index].append(c)
+
+