Advertisement
Guest User

Untitled

a guest
May 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. import datetime as dt
  2. import easygui as eg
  3. import sqlite3
  4. import datetime as dt
  5. import smtplib
  6. import win32gui
  7. import re
  8. import pandas as pd
  9. # from selenium.webdriver import Firefox
  10. from selenium import webdriver
  11.  
  12. DATABASE = (r"C:\FINANCE\Python\PyCharm\Projects\EconomicCalendar3\EconCalDb3.db")
  13. fromaddr = 'josef.kirsh01@gmail.com'
  14. toaddrs = 'josef.kirsh01@gmail.com'
  15. msg = 'There was a terrible error that occured and I wanted you to know!'
  16.  
  17.  
  18. class WindowMgr:
  19. """Encapsulates some calls to the winapi for window management"""
  20.  
  21. def __init__(self):
  22. """Constructor"""
  23. self._handle = None
  24.  
  25. def find_window(self, class_name, window_name=None):
  26. """find a window by its class_name"""
  27. self._handle = win32gui.FindWindow(class_name, window_name)
  28.  
  29. def _window_enum_callback(self, hwnd, wildcard):
  30. '''Pass to win32gui.EnumWindows() to check all the opened windows'''
  31. # if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) != None:
  32. if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) is not None:
  33. self._handle = hwnd
  34.  
  35. def find_window_wildcard(self, wildcard):
  36. self._handle = None
  37. win32gui.EnumWindows(self._window_enum_callback, wildcard)
  38.  
  39. def set_foreground(self):
  40. """put the window in the foreground"""
  41. win32gui.SetForegroundWindow(self._handle)
  42.  
  43.  
  44. sql = '''
  45. SELECT Date, ETtime,
  46. Release FROM Briefing
  47. WHERE date BETWEEN ? AND ?
  48. '''
  49.  
  50.  
  51. def Send_mail():
  52. # Credentials (if needed)
  53. username = 'josef.kirsh01'
  54. password = 'diana123'
  55.  
  56. # The actual mail send
  57. server = smtplib.SMTP('smtp.gmail.com:587')
  58. server.starttls()
  59. server.login(username, password)
  60. server.sendmail(fromaddr, toaddrs, msg)
  61. server.quit()
  62.  
  63.  
  64. today = dt.date.today()
  65. yr = int(today.strftime("%Y"))
  66.  
  67.  
  68. def get_week_year():
  69. WeekOfYear = int(today.strftime("%U"))
  70. # WeekOfYear = int(today.strftime("%U")) + 1
  71. return WeekOfYear
  72.  
  73.  
  74. def get_week_days(year, week):
  75. d = dt.date(year, 1, 1)
  76. if (d.weekday() > 3):
  77. d = d + dt.timedelta(7 - d.weekday())
  78. else:
  79. d = d - dt.timedelta(d.weekday())
  80. dlt = dt.timedelta(days=(week - 1) * 7)
  81. # startday = '{d.year}-{d.month}-{d.day}'.format(d=(d + dlt) ) # Remove leading Zero's
  82. # endday = '{d.year}-{d.month}-{d.day}'.format(d=(d + dlt + dt.timedelta(days=4)) ) # Remove leading Zero's
  83. startday = d + dlt
  84. endday = d + dlt + dt.timedelta(days=4)
  85. return startday, endday
  86.  
  87.  
  88. ##################### Main ########################
  89. if __name__ == '__main__':
  90. WeekNum = get_week_year()
  91. StartDay, EndDay = (get_week_days(yr, WeekNum))
  92.  
  93. try:
  94. conn = sqlite3.connect(DATABASE)
  95. # Data = pd.read_sql('SELECT Strike, CallsOI, PutsOI FROM t_LastDayOI' , conn)
  96. Data = pd.read_sql(sql, conn, params=[StartDay, EndDay])
  97. except sqlite3.Error as er:
  98. # Something is wrong with the database
  99. print 'er', er.message
  100. conn.close()
  101. # print (Data)
  102. Data.to_html('jkfile.html')
  103. driver = webdriver.Firefox()
  104. # driver.set_window_size(1024, 768)
  105. driver.set_window_size(414,512)
  106. # driver = webdriver.PhantomJS()
  107. # driver.implicitly_wait(30)
  108. # driver.get('C:\FINANCE\Python\PyCharm\Projects\EconomicCalendar3\jkfile.html')
  109. driver.get('file:///C:/FINANCE/Python/PyCharm/Projects/EconomicCalendar3/jkfile.html')
  110. # import webbrowser
  111. # # webbrowser
  112. # webbrowser.open('jkfile.html')
  113. # webbrowser.open()
  114. # db = sqlite3.connect(DATABASE)
  115. # cursor = db.cursor()
  116. # cursor.execute(sql, (StartDay, EndDay))
  117. # all_rows = cursor.fetchall()
  118. # Str_all_rows = '\n'.join(str(e) for e in all_rows)
  119. #
  120. # eg.textbox(msg="", title="EconCal", text=Str_all_rows, codebox=0)
  121. # db.close()
  122. conn.close()
  123. # w = WindowMgr()
  124. # w.find_window_wildcard(".*EconCal.*")
  125. # w.set_foreground()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement