Guest User

Untitled

a guest
Nov 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.79 KB | None | 0 0
  1. diff --git a/bulkreg.py b/bulkreg.py
  2. index 8e009d3..6cdb391 100644
  3. --- a/bulkreg.py
  4. +++ b/bulkreg.py
  5. @@ -21,7 +21,7 @@ def process_bulk(magtek_ip, amount, num=200, until=None, docfeed="AUTOFEED",):
  6.      id_file = open('id')
  7.      cur_id = int(id_file.readline())
  8.      id_file.close()
  9. -    out_file = open('results.csv','ab')
  10. +    out_file = open('results.csv','a')
  11.      csvfile = csv.DictWriter(out_file,['check_id','amount','checknum'])
  12.      csvfile.out_file = out_file
  13.      row = {'check_id': None, 'amount': amount, 'checknum': None}
  14. @@ -39,10 +39,13 @@ def process_bulk(magtek_ip, amount, num=200, until=None, docfeed="AUTOFEED",):
  15.      print("Scanned %d checks." % num)
  16.  
  17.  def process_check(mtk, csvfile, row):
  18. +    print(row)
  19.      mtk.images[0]['save_as'] = 'checks/%(check_id)s.jpg' % row
  20.      try:
  21.          mtk.execute()
  22. -    except AttributeError:
  23. +    except AttributeError as e:
  24. +        print(e)
  25. +        raise e
  26.          print("No checks remaining.")
  27.          return False
  28.      if not mtk.feed_ok:
  29. @@ -55,6 +58,7 @@ def process_check(mtk, csvfile, row):
  30.          if row['checknum'] == 'x':
  31.              os.remove(mtk.images[0]['save_as'])
  32.              return False
  33. +    print(row)
  34.      csvfile.writerow(row)
  35.      csvfile.out_file.flush()
  36.      print("Wrote", row)
  37. diff --git a/magtek.py b/magtek.py
  38. index 4bfb9b6..52e3e66 100644
  39. --- a/magtek.py
  40. +++ b/magtek.py
  41. @@ -1,8 +1,9 @@
  42.  
  43.  import os
  44.  import pycurl
  45. -from StringIO import StringIO
  46. -from xml.etree.ElementTree import XMLTreeBuilder
  47. +# from StringIO import StringIO
  48. +from io import BytesIO
  49. +from xml.etree.ElementTree import XMLParser
  50.  
  51.  def detect_ip_from_env():
  52.      if 'MAGTEK_IP' in os.environ:
  53. @@ -61,7 +62,7 @@ class Scanner:
  54.                  # Initialize the request curl object
  55.                  self._curl_request = pycurl.Curl()
  56.                  self._curl_request.setopt(pycurl.URL, self._url_base + self.REQUEST_SUFFIX)
  57. -                self._result_buffer = StringIO()
  58. +                self._result_buffer = BytesIO()
  59.                  self._curl_request.setopt(pycurl.WRITEFUNCTION, self._result_buffer.write)
  60.                  self._curl_request.setopt(pycurl.POST, 1)
  61.  
  62. @@ -120,9 +121,12 @@ class Scanner:
  63.                  self._result_buffer.truncate()
  64.                  self._result_buffer.seek(0)
  65.  
  66. -                xml = XMLTreeBuilder()
  67. -                xml.feed(self._result_buffer.read())
  68. +                xml = XMLParser()
  69. +                s = self._result_buffer.read()
  70. +                # print(s)
  71. +                xml.feed(s)
  72.                  self.result = xml.close()
  73. +                # print(self.result)
  74.  
  75.                  self.micr_ok = self.get_param(['DocInfo','MICRDecode']) == 'OK'
  76.                  self.feed_ok = self.get_param(['CommandStatus','ReturnCode']) == '0'
  77. @@ -131,6 +135,7 @@ class Scanner:
  78.                          self.fetch_images()
  79.  
  80.          def get_param(self, keys):
  81. +                print(self.result)
  82.                  xml = self.result
  83.                  for k in keys:
  84.                          xml = xml.find(k)
  85. @@ -157,7 +162,7 @@ if __name__ == '__main__':
  86.              magtek_ip = '192.168.160.2'  # USB
  87.              magtek_ip = '192.168.10.100' # Ethernet
  88.          mtk = Scanner(url_base="http://%s" % (magtek_ip, ), docfeed="MANUAL")
  89. -        print mtk._url_base + mtk.REQUEST_SUFFIX
  90. -        print mtk.request
  91. -        print '\n'
  92. +        print(mtk._url_base + mtk.REQUEST_SUFFIX)
  93. +        print(mtk.request)
  94. +        print('\n')
  95.          mtk.execute()
  96. diff --git a/make_deposit.py b/make_deposit.py
  97. index 76bcbd6..4cbda75 100644
  98. --- a/make_deposit.py
  99. +++ b/make_deposit.py
  100. @@ -12,6 +12,8 @@ import re
  101.  from decimal import Decimal
  102.  from datetime import datetime
  103.  
  104. +raw_input = input
  105. +
  106.  def decimal_from_dollar_string(s):
  107.      """
  108.  Takes a string s.
  109. @@ -34,7 +36,7 @@ Until the user enters a string in the format expected by decimal_from_dollar_sig
  110.      return d
  111.  
  112.  if len(sys.argv) == 1:
  113. -    print __doc__
  114. +    print(__doc__)
  115.      sys.exit()
  116.  
  117.  if len(sys.argv) > 3:
  118. @@ -50,6 +52,7 @@ check_sum = 0
  119.  for line in csv.reader(in_file):
  120.      if (lo is None and hi is None) or (int(line[0]) >= lo and int(line[0]) <= hi):
  121.          lines.append(line)
  122. +        print(line)
  123.          check_sum += Decimal(line[1])
  124.  in_file.close()
  125.  check_num = len(lines)
  126. @@ -57,7 +60,7 @@ check_num = len(lines)
  127.  out_fn = 'deposit.csv'
  128.  out_fn = sys.argv[1]
  129.  
  130. -out_file = open(out_fn, 'wb')
  131. +out_file = open(out_fn, 'w')
  132.  out_csv = csv.writer(out_file)
  133.  
  134.  settings_file = None
  135. @@ -98,7 +101,7 @@ it = iter(lines)
  136.  row = []
  137.  while True:
  138.      try:
  139. -        check = it.next()
  140. +        check = next(it)
  141.          check[1] = Decimal(check[1])
  142.          if len(row) == 0:
  143.              row += check
  144. ~
  145. ~
  146. ~
  147. ~
  148. ~
  149. ~
  150. ~
  151. ~
  152. ~
  153. ~
  154. ~
  155. ~
  156. ~
  157. ~
  158. ~
  159. ~
  160. ~
  161. ~
  162. ~
  163. ~
  164. ~
  165. ~
  166. ~
  167. ~
  168. ~
  169. ~
  170. ~
  171. ~
  172. ~
  173. ~
  174. ~
  175. ~
  176. ~
  177. ~
  178. ~
  179. ~
  180. ~
  181. ~
  182. ~
  183. ~
  184. ~
  185. ~
  186. ~
  187. ~
  188. ~
  189. ~
  190. ~
  191. ~
  192. ~
  193. ~
  194. ~
  195. ~
  196. ~
  197. ~
  198. check-scanner.diff [unix] (20:27 21/11/2019)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 1,1 All
Advertisement
Add Comment
Please, Sign In to add comment