Created
December 15, 2011 09:18
Split your tiresome EE member xml files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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