4월, 2010의 게시물 표시

pdf 를 txt 로 converting 하는 방법. xpdf - pdftotxt

새로 투입된 프로젝트에서 기존 레거시 소스를 수정해야 하는 일을 맡았다. 그런데 소스를 pdf 파일로 주는것이 아닌가.... ㅜㅜ 한두개도 아니고 그많은 소스를 손으로 칠수도 없고... pdf 를 txt 형태로 바꾸는 방법을 찾아 보았다. python 의 pyPdf 모듈을 쓰면된다고 한다. ================================ import pyPdf def getPDFContent(path):     content = ""     # Load PDF into pyPDF     print path     pdf = pyPdf.PdfFileReader(file(path, "rb"))     # Iterate pages        for i in range(0, pdf.getNumPages()):         # Extract text from page and add to content         content += pdf.getPage(i).extractText() + "\n"     # Collapse whitespace     #content = " ".join(content.replace(u"\xa0", " ").strip().split())     return conten ==================================== 이방법엔 한가지 문제가 있다. 소스 아웃라인을 무시하고 그냥 쭈욱~ 연결한 변환파일을 만들어 낸다. 다시 해결책을 찾다가 더 손쉬운 방법을 찾았다. pdftotext 라는 편리한 툴!!! xpdf 라는 pdf 관련툴의 한 부분인것 같다. 명령어는 다음과 같다. pdftotext -layout -nopgbrk source_pdf_file_name dest_txt_file_name python 으로 system 모듈을 이용 약 12

python twisted UPDATE query 처리 예제.

python twisted 를 시작했다. 생각보다 쉽지 않다. 특히 deferred 가 어렵다. 문서화가 잘되 있지 않아 (있긴하지만 초보에게 친절하지 않다) 이해가 안된다. 3일을 끙끙대며 예제를 따라 갔는데 DB update 방법을 몰라서 고생했다. twisted IRC 에 접속해 물어 봐서 간신히 방법을 알아 냈다. 바로 runInteraction 을이용해야 한다는거다. 잊어버릴것 같아 예제를 기록해 둔다.  ============================================ from twisted.internet import epollreactor epollreactor.install() from twisted.internet import reactor,threads from twisted.python import log from twisted.enterprise import adbapi import time dbpool = adbapi.ConnectionPool('cx_Oracle',dsn='mydsn',user='irts',password='irts') def updateProc(txn):     result = (True, )     try:         txn.execute('UPDATE AVISTATE set ONLINEFLAG=0 where (sysdate - updatedate)*24*60*60 > 120')         result = (True,)     except Exception,e:         result = (False,e)     return result def getAVIID():     return dbpool.runInteraction(updateProc) def printResult(x):     if x[0]:         print 'Updatge s