Skip to content

Commit

Permalink
updated code for api updates and added tests and sample
Browse files Browse the repository at this point in the history
  • Loading branch information
anjesh committed Jul 26, 2016
1 parent 264b6ee commit 2b51c70
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
8 changes: 5 additions & 3 deletions abbyy/AbbyyOnlineSdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def GetTaskStatus( self, task ):
return task

def DownloadResult( self, task, outputPath ):
getResultParams = urllib.urlencode( { "taskId" : task.Id } )
getResultUrl = self.ServerUrl + "getResult?" + getResultParams
request = urllib2.Request( getResultUrl, None, self.buildAuthInfo() )
getResultUrl = task.DownloadUrl
if getResultUrl == None :
print "No download URL found"
return
request = urllib2.Request( getResultUrl )
fileResponse = self.getOpener().open( request ).read()
resultFile = open( outputPath, "wb" )
resultFile.write( fileResponse )
Expand Down
44 changes: 44 additions & 0 deletions tests/AbbyyPdfTextExtractorNetworkTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/local/bin/python

import unittest
import sys
import os.path
import glob
import ConfigParser
from pdftools.PdfSeparate import *
from abbyy.AbbyyPdfTextExtractor import *
from urllib2 import HTTPError

class AbbyyPdfTextExtractorNetworkTest(unittest.TestCase):
def setUp(self):
self.outdir = "tests/out/abbyy/text"
self.indir = "tests/out/abbyy/pdf"
self.createOrCleanDir(self.outdir)
self.createOrCleanDir(self.indir)
self.configParser = ConfigParser.RawConfigParser()
self.configParser.read('settings.config')


def createOrCleanDir(self, directory):
if not os.path.exists(directory):
os.makedirs(directory)
else:
files = glob.glob(directory)
for f in files:
if os.path.isfile(f):
os.remove(f)

def testScanned44PdfPageForNetwork(self):
pdfSeparate = PdfSeparate('tests/sample-scanned-44pages.pdf', self.indir)
pdfSeparate.extractPages()
self.assertTrue(os.path.isfile(os.path.join(self.indir,"1.pdf")))

try:
abbyyPdf = AbbyyPdfTextExtractor(self.indir, self.outdir, 44, "english")
abbyyPdf.setApplicationCredentials(self.configParser.get('abbyy','appid'), self.configParser.get('abbyy','password'))
abbyyPdf.extractPages();
self.assertTrue(os.path.isfile(os.path.join(self.outdir,"1.txt")))
self.assertTrue(os.path.isfile(os.path.join(self.outdir,"44.txt")))
except Exception:
pass

Binary file added tests/sample-scanned-44pages.pdf
Binary file not shown.

0 comments on commit 2b51c70

Please sign in to comment.