PageRenderTime 59ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/utilities/filterWikiColumns.py

https://github.com/Arkanosis/Wikipedia
Python | 22 lines | 16 code | 5 blank | 1 comment | 7 complexity | 2455a208595503dcf0643f898c54a1b2 MD5 | raw file
  1. #! /usr/bin/python
  2. from __future__ import with_statement
  3. import sys
  4. if len(sys.argv) != 4:
  5. print 'Usage:', sys.argv[0], '<input> <output> <column>'
  6. sys.exit(1)
  7. column = int(sys.argv[3])
  8. currentColumn = 0
  9. with open(sys.argv[1]) as inputFile:
  10. with open(sys.argv[2], 'w') as outputFile:
  11. for line in inputFile:
  12. if currentColumn == column:
  13. outputFile.write(line)
  14. if line.startswith('|-'):
  15. currentColumn = 1
  16. else:
  17. currentColumn += 1