Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/bulkreg.py b/bulkreg.py
- index 8e009d3..6cdb391 100644
- --- a/bulkreg.py
- +++ b/bulkreg.py
- @@ -21,7 +21,7 @@ def process_bulk(magtek_ip, amount, num=200, until=None, docfeed="AUTOFEED",):
- id_file = open('id')
- cur_id = int(id_file.readline())
- id_file.close()
- - out_file = open('results.csv','ab')
- + out_file = open('results.csv','a')
- csvfile = csv.DictWriter(out_file,['check_id','amount','checknum'])
- csvfile.out_file = out_file
- row = {'check_id': None, 'amount': amount, 'checknum': None}
- @@ -39,10 +39,13 @@ def process_bulk(magtek_ip, amount, num=200, until=None, docfeed="AUTOFEED",):
- print("Scanned %d checks." % num)
- def process_check(mtk, csvfile, row):
- + print(row)
- mtk.images[0]['save_as'] = 'checks/%(check_id)s.jpg' % row
- try:
- mtk.execute()
- - except AttributeError:
- + except AttributeError as e:
- + print(e)
- + raise e
- print("No checks remaining.")
- return False
- if not mtk.feed_ok:
- @@ -55,6 +58,7 @@ def process_check(mtk, csvfile, row):
- if row['checknum'] == 'x':
- os.remove(mtk.images[0]['save_as'])
- return False
- + print(row)
- csvfile.writerow(row)
- csvfile.out_file.flush()
- print("Wrote", row)
- diff --git a/magtek.py b/magtek.py
- index 4bfb9b6..52e3e66 100644
- --- a/magtek.py
- +++ b/magtek.py
- @@ -1,8 +1,9 @@
- import os
- import pycurl
- -from StringIO import StringIO
- -from xml.etree.ElementTree import XMLTreeBuilder
- +# from StringIO import StringIO
- +from io import BytesIO
- +from xml.etree.ElementTree import XMLParser
- def detect_ip_from_env():
- if 'MAGTEK_IP' in os.environ:
- @@ -61,7 +62,7 @@ class Scanner:
- # Initialize the request curl object
- self._curl_request = pycurl.Curl()
- self._curl_request.setopt(pycurl.URL, self._url_base + self.REQUEST_SUFFIX)
- - self._result_buffer = StringIO()
- + self._result_buffer = BytesIO()
- self._curl_request.setopt(pycurl.WRITEFUNCTION, self._result_buffer.write)
- self._curl_request.setopt(pycurl.POST, 1)
- @@ -120,9 +121,12 @@ class Scanner:
- self._result_buffer.truncate()
- self._result_buffer.seek(0)
- - xml = XMLTreeBuilder()
- - xml.feed(self._result_buffer.read())
- + xml = XMLParser()
- + s = self._result_buffer.read()
- + # print(s)
- + xml.feed(s)
- self.result = xml.close()
- + # print(self.result)
- self.micr_ok = self.get_param(['DocInfo','MICRDecode']) == 'OK'
- self.feed_ok = self.get_param(['CommandStatus','ReturnCode']) == '0'
- @@ -131,6 +135,7 @@ class Scanner:
- self.fetch_images()
- def get_param(self, keys):
- + print(self.result)
- xml = self.result
- for k in keys:
- xml = xml.find(k)
- @@ -157,7 +162,7 @@ if __name__ == '__main__':
- magtek_ip = '192.168.160.2' # USB
- magtek_ip = '192.168.10.100' # Ethernet
- mtk = Scanner(url_base="http://%s" % (magtek_ip, ), docfeed="MANUAL")
- - print mtk._url_base + mtk.REQUEST_SUFFIX
- - print mtk.request
- - print '\n'
- + print(mtk._url_base + mtk.REQUEST_SUFFIX)
- + print(mtk.request)
- + print('\n')
- mtk.execute()
- diff --git a/make_deposit.py b/make_deposit.py
- index 76bcbd6..4cbda75 100644
- --- a/make_deposit.py
- +++ b/make_deposit.py
- @@ -12,6 +12,8 @@ import re
- from decimal import Decimal
- from datetime import datetime
- +raw_input = input
- +
- def decimal_from_dollar_string(s):
- """
- Takes a string s.
- @@ -34,7 +36,7 @@ Until the user enters a string in the format expected by decimal_from_dollar_sig
- return d
- if len(sys.argv) == 1:
- - print __doc__
- + print(__doc__)
- sys.exit()
- if len(sys.argv) > 3:
- @@ -50,6 +52,7 @@ check_sum = 0
- for line in csv.reader(in_file):
- if (lo is None and hi is None) or (int(line[0]) >= lo and int(line[0]) <= hi):
- lines.append(line)
- + print(line)
- check_sum += Decimal(line[1])
- in_file.close()
- check_num = len(lines)
- @@ -57,7 +60,7 @@ check_num = len(lines)
- out_fn = 'deposit.csv'
- out_fn = sys.argv[1]
- -out_file = open(out_fn, 'wb')
- +out_file = open(out_fn, 'w')
- out_csv = csv.writer(out_file)
- settings_file = None
- @@ -98,7 +101,7 @@ it = iter(lines)
- row = []
- while True:
- try:
- - check = it.next()
- + check = next(it)
- check[1] = Decimal(check[1])
- if len(row) == 0:
- row += check
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- ~
- check-scanner.diff [unix] (20:27 21/11/2019) 1,1 All
Advertisement
Add Comment
Please, Sign In to add comment