xjc hace 4 años
padre
commit
a85fac5bf5
Se han modificado 4 ficheros con 96 adiciones y 30 borrados
  1. 43 0
      service.log
  2. 1 0
      twainscan.py
  3. BIN
      twainscan.pyc
  4. 52 30
      xscanserver.py

+ 43 - 0
service.log

@@ -340,3 +340,46 @@
 2021-10-29 14:04:41,351 [PythonService] ERROR    None
 2021-10-29 14:04:41,351 [PythonService] ERROR    'NoneType' object has no attribute 'SaveAs'
 2021-10-29 14:04:41,351 [PythonService] ERROR    'NoneType' object has no attribute 'SaveAs'
+2021-11-01 21:46:22,726 [PythonService] INFO     服务正在运行...
+2021-11-01 21:46:43,295 [PythonService] ERROR    c:\AppData\say365\1635774401514.docx
+2021-11-01 21:46:43,296 [PythonService] INFO     Microsoft Word
+2021-11-01 21:46:44,184 [PythonService] ERROR    1635774401514.docx
+2021-11-01 21:46:46,259 [PythonService] INFO     test
+2021-11-01 21:46:54,507 [PythonService] ERROR    c:\AppData\say365\1635774413050.docx
+2021-11-01 21:46:54,507 [PythonService] INFO     Microsoft Word
+2021-11-01 21:46:55,437 [PythonService] ERROR    1635774413050.docx
+2021-11-01 21:46:56,548 [PythonService] INFO     test
+2021-11-01 21:48:25,303 [PythonService] ERROR    c:\AppData\say365\1635774504146.docx
+2021-11-01 21:48:25,305 [PythonService] INFO     Microsoft Word
+2021-11-01 21:48:26,256 [PythonService] ERROR    1635774504146.docx
+2021-11-01 21:48:27,392 [PythonService] INFO     test
+2021-11-01 21:48:37,677 [PythonService] ERROR    c:\AppData\say365\1635774516521.docx
+2021-11-01 21:48:37,677 [PythonService] INFO     Microsoft Word
+2021-11-01 21:48:38,589 [PythonService] ERROR    1635774516521.docx
+2021-11-01 21:48:39,757 [PythonService] INFO     test
+2021-11-01 21:48:46,740 [PythonService] ERROR    c:\AppData\say365\1635774525582.docx
+2021-11-01 21:48:46,740 [PythonService] INFO     Microsoft Word
+2021-11-01 21:48:47,661 [PythonService] ERROR    1635774525582.docx
+2021-11-01 21:48:48,792 [PythonService] INFO     test
+2021-11-01 21:50:02,737 [PythonService] INFO     服务正在运行...
+2021-11-01 21:50:23,456 [PythonService] ERROR    c:\AppData\say365\1635774622308.docx
+2021-11-01 21:50:23,457 [PythonService] INFO     Microsoft Word
+2021-11-01 21:50:24,404 [PythonService] ERROR    1635774622308.docx
+2021-11-01 21:50:25,523 [PythonService] INFO     test
+2021-11-01 21:51:18,187 [PythonService] ERROR    c:\AppData\say365\1635774677037.docx
+2021-11-01 21:51:18,187 [PythonService] INFO     Microsoft Word
+2021-11-01 21:51:19,091 [PythonService] ERROR    1635774677037.docx
+2021-11-01 21:51:20,242 [PythonService] INFO     test
+2021-11-01 21:53:19,173 [PythonService] INFO     服务正在运行...
+2021-11-01 21:54:25,131 [PythonService] ERROR    c:\AppData\say365\1635774862710.docx
+2021-11-01 21:54:25,134 [PythonService] INFO     Microsoft Word
+2021-11-01 21:54:26,823 [PythonService] ERROR    1635774862710.docx
+2021-11-01 21:54:28,381 [PythonService] INFO     test
+2021-11-01 22:05:30,459 [PythonService] ERROR    c:\AppData\say365\1635775528424.docx
+2021-11-01 22:05:30,460 [PythonService] INFO     Microsoft Word
+2021-11-01 22:05:31,552 [PythonService] ERROR    1635775528424.docx
+2021-11-01 22:05:33,243 [PythonService] INFO     test
+2021-11-01 22:05:53,539 [PythonService] ERROR    c:\AppData\say365\1635775552110.docx
+2021-11-01 22:05:53,540 [PythonService] INFO     Microsoft Word
+2021-11-01 22:05:54,644 [PythonService] ERROR    1635775552110.docx
+2021-11-01 22:05:55,967 [PythonService] INFO     test

+ 1 - 0
twainscan.py

@@ -11,6 +11,7 @@ import json
 from Queue import Queue
 from threading import Thread
 from multiprocessing import Process
+from threading import Thread
 
 reload(sys)
 sys.setdefaultencoding("utf-8")

BIN
twainscan.pyc


+ 52 - 30
xscanserver.py

@@ -12,11 +12,13 @@ import win32service
 import servicemanager
 import win32serviceutil
 
-from flask import Flask,request
+from flask import Flask,request,make_response,jsonify
+from flask_cors import *
 
 from tornado.ioloop import IOLoop
 from tornado.wsgi import WSGIContainer
 from tornado.httpserver import HTTPServer
+from threading import Thread
 
 #from parsedocx import DocxConverter,QuestionsParser
 
@@ -25,6 +27,19 @@ import json,uuid
 from bs4 import BeautifulSoup
 from win32com.client import Dispatch,DispatchEx
 import pythoncom
+from twainscan import get_source_names,start_scan
+
+app = Flask(__name__)
+CORS(app,supports_credentials=True)
+root = "c:\\AppData\\say365"
+xlog = logging.getLogger('[PythonService]')
+handler = logging.FileHandler(os.path.join(root, "service.log"))
+
+formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
+handler.setFormatter(formatter)
+
+xlog.addHandler(handler)
+xlog.setLevel(logging.INFO)
 
 
 class DocxConverter(object):
@@ -130,20 +145,7 @@ class QuestionsParser(object):
         qno = re.search(r"\d+",tgtext.split(u"、")[0]).group()
         return qno
 
-
-
-app = Flask(__name__)
-root = "c:\\AppData\\say365"
-xlog = logging.getLogger('[PythonService]')
-handler = logging.FileHandler(os.path.join(root, "service.log"))
-
-formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
-handler.setFormatter(formatter)
-
-xlog.addHandler(handler)
-xlog.setLevel(logging.INFO)
-
-@app.route('/parsedocx',methods=["POST"])
+@app.route('/parsedocx.aspx',methods=["POST"])
 def parsedocx():
     """
     """
@@ -167,12 +169,32 @@ def parsedocx():
     except Exception as e:
         xlog.error(e)
         return str(e)
+        
+@app.route('/xscanSourceList.aspx',methods=["GET"])
+def xscanSourceList():
+    """
+    """
+    snames = get_source_names()
+    res = make_response(jsonify(snames))
+    return res
+        
+@app.route('/xscanAction.aspx',methods=["GET"])
+def xscanAction():
+    """
+    """
+    try:
+        t = Thread(target = start_scan)
+        t.start()
+        return "success"
+    except Exception as e:
+        xlog.error(e)
+        return str(e)
     
 
 def main():
     #app.run(host='0.0.0.0', port=8002, debug=True)
     s = HTTPServer(WSGIContainer(app))
-    s.listen(8002)
+    s.listen(19882)
     IOLoop.current().start()
  
 class XsacnService(win32serviceutil.ServiceFramework): 
@@ -215,7 +237,7 @@ class XsacnService(win32serviceutil.ServiceFramework):
         while self.isAlive:
             self.logger.info("服务正在运行...")
             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            result = sock.connect_ex(('127.0.0.1', 8002))  # 嗅探网址是否可以访问,成功返回0,出错返回错误码
+            result = sock.connect_ex(('127.0.0.1', 19882))  # 嗅探网址是否可以访问,成功返回0,出错返回错误码
             if result != 0:
                 # Python3.8的asyncio改变了循环方式,因为这种方式在windows上不支持相应的add_reader APIs,就会抛出NotImplementedError错误。
                 # 因此加入下面两行代码
@@ -228,7 +250,7 @@ class XsacnService(win32serviceutil.ServiceFramework):
     def main(self):
         #app.run(host='0.0.0.0', port=8002, debug=True)
         s = HTTPServer(WSGIContainer(app))
-        s.listen(8002)
+        s.listen(19882)
         IOLoop.current().start()            
             
     def SvcStop(self): 
@@ -240,15 +262,15 @@ class XsacnService(win32serviceutil.ServiceFramework):
         
  
 if __name__=='__main__': 
-    if len(sys.argv) == 1:
-        try:
-            evtsrc_dll = os.path.abspath(servicemanager.__file__)
-            servicemanager.PrepareToHostSingle(XsacnService)
-            servicemanager.Initialize('XsacnService', evtsrc_dll)
-            servicemanager.StartServiceCtrlDispatcher()
-        except win32service.error, details:
-            if details[0] == winerror.ERROR_FAILED_SERVICE_CONTROLLER_CONNECT:
-                win32serviceutil.usage()
-    else:
-        win32serviceutil.HandleCommandLine(XsacnService)
-    #main()
+    #if len(sys.argv) == 1:
+    #    try:
+    #        evtsrc_dll = os.path.abspath(servicemanager.__file__)
+    #        servicemanager.PrepareToHostSingle(XsacnService)
+    #        servicemanager.Initialize('XsacnService', evtsrc_dll)
+    #        servicemanager.StartServiceCtrlDispatcher()
+    #    except win32service.error, details:
+    #        if details[0] == winerror.ERROR_FAILED_SERVICE_CONTROLLER_CONNECT:
+    #            win32serviceutil.usage()
+    #else:
+    #    win32serviceutil.HandleCommandLine(XsacnService)
+    main()