com_read_data.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. import codecs
  3. import time
  4. import traceback
  5. import sys
  6. import time
  7. from datetime import date
  8. import datetime
  9. import traceback
  10. import os
  11. import subprocess
  12. import ctypes
  13. import time
  14. import os
  15. import pythoncom
  16. import win32com
  17. import win32com.client
  18. from subprocess import Popen
  19. import threading
  20. import traceback
  21. def gen_and_save(AB,itemnum,tabnum,fname):
  22. width=1024
  23. height=768
  24. AB.Documents.Item(itemnum).Windows.Item(0).Activate()
  25. AB.ActiveDocument.ActiveWindow.SelectedTab=tabnum
  26. AW = AB.Documents.Item(itemnum).Windows.Item(0)
  27. prefix='c:/gitlab/win10-forex/static'
  28. img = prefix+"/"+fname
  29. print(AW.ExportImage( img,width,height))
  30. time.sleep(0.2)
  31. def runTA():
  32. try:
  33. width=1024
  34. height=768
  35. dtnow=datetime.datetime.now()
  36. si = subprocess.STARTUPINFO()
  37. si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  38. AB = win32com.client.Dispatch("Broker.Application")
  39. pythoncom.CoInitialize()
  40. AB.Documents.Item(0).Windows.Item(0).Activate()
  41. AB.ActiveDocument.ActiveWindow.SelectedTab=0
  42. time.sleep(4)
  43. # gen_and_save(AB,0,0,'ec.png')
  44. # gen_and_save(AB,2,0,'cad.png')
  45. # gen_and_save(AB,2,1,'ydx.png')
  46. # gen_and_save(AB,4,0,'day.png')
  47. AB.SaveDatabase()
  48. pythoncom.CoUninitialize()
  49. except Exception:
  50. print("exception ")
  51. traceback.print_exc()
  52. runTA()