Skip to content

Instantly share code, notes, and snippets.

@trcook
Created August 18, 2014 02:36
Show Gist options
  • Save trcook/eadc86ab302d6090dfa8 to your computer and use it in GitHub Desktop.
Save trcook/eadc86ab302d6090dfa8 to your computer and use it in GitHub Desktop.
this will change directories as directed, open a file, match by a regex and then print out the results ot a file as directed
#! #!/usr/bin/env python3
import io, os, re
os.chdir('/Users/tom/Desktop/tmp')
e=open('questiondb.xml','rt')
search_string=e.read()
e.close()
outfile=open("out.txt",'w')
matches=re.findall(r"(<item d2l_2p0:id=.*\n(.+?\n(?!</item))+?.*?questiontype(.*?\n)+?.*Multiple Choice\n(.*\n)+?.*/item>.*?\n)",search_string)
for i in matches:
outfile.write(i[0])
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment