Skip to content

Instantly share code, notes, and snippets.

@qbyt
Created December 15, 2011 09:18
Show Gist options
  • Save qbyt/1480475 to your computer and use it in GitHub Desktop.
Save qbyt/1480475 to your computer and use it in GitHub Desktop.
Split your tiresome EE member xml files
#!/usr/bin/env python
# encoding: utf-8
import os
from BeautifulSoup import BeautifulStoneSoup
def brew(path):
""" Creates the brew, extracts the members """
doc = open(path, 'r')
brew = BeautifulStoneSoup(doc)
return brew.findAll('member')
def split(c, n):
""" Yield successive n-sized splits from c. """
for i in xrange(0, len(c), n):
yield c[i:i+n]
if __name__ == '__main__':
""" No more soup, just XML """
cwd = os.getcwd()
members = brew('%s/../setup/member_xml.xml' % (cwd))
groups = split(members, 500) # 500 means fewer crapouts
for group in enumerate(groups):
path = '%s/group_%s.xml' % (cwd, group[0])
output = '<members>%s</members>' % (''.join(str(member) for member in group[1]))
outfile = open(path, 'w')
outfile.write(output)
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment