Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime as dt
- import easygui as eg
- import sqlite3
- import datetime as dt
- import smtplib
- import win32gui
- import re
- import pandas as pd
- # from selenium.webdriver import Firefox
- from selenium import webdriver
- DATABASE = (r"C:\FINANCE\Python\PyCharm\Projects\EconomicCalendar3\EconCalDb3.db")
- fromaddr = 'josef.kirsh01@gmail.com'
- toaddrs = 'josef.kirsh01@gmail.com'
- msg = 'There was a terrible error that occured and I wanted you to know!'
- class WindowMgr:
- """Encapsulates some calls to the winapi for window management"""
- def __init__(self):
- """Constructor"""
- self._handle = None
- def find_window(self, class_name, window_name=None):
- """find a window by its class_name"""
- self._handle = win32gui.FindWindow(class_name, window_name)
- def _window_enum_callback(self, hwnd, wildcard):
- '''Pass to win32gui.EnumWindows() to check all the opened windows'''
- # if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) != None:
- if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) is not None:
- self._handle = hwnd
- def find_window_wildcard(self, wildcard):
- self._handle = None
- win32gui.EnumWindows(self._window_enum_callback, wildcard)
- def set_foreground(self):
- """put the window in the foreground"""
- win32gui.SetForegroundWindow(self._handle)
- sql = '''
- SELECT Date, ETtime,
- Release FROM Briefing
- WHERE date BETWEEN ? AND ?
- '''
- def Send_mail():
- # Credentials (if needed)
- username = 'josef.kirsh01'
- password = 'diana123'
- # The actual mail send
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username, password)
- server.sendmail(fromaddr, toaddrs, msg)
- server.quit()
- today = dt.date.today()
- yr = int(today.strftime("%Y"))
- def get_week_year():
- WeekOfYear = int(today.strftime("%U"))
- # WeekOfYear = int(today.strftime("%U")) + 1
- return WeekOfYear
- def get_week_days(year, week):
- d = dt.date(year, 1, 1)
- if (d.weekday() > 3):
- d = d + dt.timedelta(7 - d.weekday())
- else:
- d = d - dt.timedelta(d.weekday())
- dlt = dt.timedelta(days=(week - 1) * 7)
- # startday = '{d.year}-{d.month}-{d.day}'.format(d=(d + dlt) ) # Remove leading Zero's
- # endday = '{d.year}-{d.month}-{d.day}'.format(d=(d + dlt + dt.timedelta(days=4)) ) # Remove leading Zero's
- startday = d + dlt
- endday = d + dlt + dt.timedelta(days=4)
- return startday, endday
- ##################### Main ########################
- if __name__ == '__main__':
- WeekNum = get_week_year()
- StartDay, EndDay = (get_week_days(yr, WeekNum))
- try:
- conn = sqlite3.connect(DATABASE)
- # Data = pd.read_sql('SELECT Strike, CallsOI, PutsOI FROM t_LastDayOI' , conn)
- Data = pd.read_sql(sql, conn, params=[StartDay, EndDay])
- except sqlite3.Error as er:
- # Something is wrong with the database
- print 'er', er.message
- conn.close()
- # print (Data)
- Data.to_html('jkfile.html')
- driver = webdriver.Firefox()
- # driver.set_window_size(1024, 768)
- driver.set_window_size(414,512)
- # driver = webdriver.PhantomJS()
- # driver.implicitly_wait(30)
- # driver.get('C:\FINANCE\Python\PyCharm\Projects\EconomicCalendar3\jkfile.html')
- driver.get('file:///C:/FINANCE/Python/PyCharm/Projects/EconomicCalendar3/jkfile.html')
- # import webbrowser
- # # webbrowser
- # webbrowser.open('jkfile.html')
- # webbrowser.open()
- # db = sqlite3.connect(DATABASE)
- # cursor = db.cursor()
- # cursor.execute(sql, (StartDay, EndDay))
- # all_rows = cursor.fetchall()
- # Str_all_rows = '\n'.join(str(e) for e in all_rows)
- #
- # eg.textbox(msg="", title="EconCal", text=Str_all_rows, codebox=0)
- # db.close()
- conn.close()
- # w = WindowMgr()
- # w.find_window_wildcard(".*EconCal.*")
- # w.set_foreground()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement