[ create a new paste ] login | about

Link: http://codepad.org/dMvGdmo0    [ raw code | fork ]

ninwa - Python, pasted on May 1:
#!/usr/bin/python

import sys
import os
import io
from subprocess import call

def main():
	filename = sys.argv[1]
	term = sys.argv[2]
	
	call(['pdftotext', filename])
	
	try:
		textfile = os.path.splitext(filename)[0] + '.txt'
		
		fh = open(textfile)
		ln = 0
		for line in fh.readlines():
			if(line.find(term) != -1):
				print 'ln ' + str(ln) + ': ' + line
			ln = ln + 1
			
		os.unlink(textfile)
	except IOError:
		print 'Error: could not open ' + filename
	
if __name__ == '__main__':
	if(len(sys.argv) != 3):
		print 'Usage: pdfsearch [pdf file] [term]'
		exit()
	else:
		main()
	


Create a new paste based on this one


Comments: