def pxi_Dam_import(): # set download directory path p = {'download.default_directory':r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\pxiDamFile'} #add options to browser opts.add_experimental_option('prefs', p) browser = Chrome(options=opts) #maximize browser browser.maximize_window() # open the website "https://www.powerexindia.com/code/frontend/Reports/DAS/MarketVolumeProfileReport.html/" browser.get('https://www.powerexindia.com/code/frontend/Reports/DAS/MarketVolumeProfileReport.html/') # click on the datepicker select button previousDate = dt.datetime.today() - dt.timedelta(days=1) previousDateFormatted = previousDate.strftime ('%d-%m-%Y') # format the date to ddmmyyyy # provide previous date to "DeliveryfromDate" browser.find_elements_by_name("DeliveryfromDate")[0].send_keys(previousDateFormatted) # provide previous date to "DeliverytoDate" browser.find_elements_by_name("DeliverytoDate")[0].send_keys(previousDateFormatted) button = browser.find_elements_by_name('submit') button[0].click() # click on different download csv option button class = "dt-button buttons-csv buttons-html5" csvDwnLd = browser.find_elements_by_tag_name("span") srcFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\pxiDamFile' destFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\pxiDamFile\Archives' destFileName = "DASMVPReport_" moveFilesToArchive(srcFileLocation, destFileLocation, destFileName) csvDwnLd[11].click() print("pxi dam fetch succesful") time.sleep(10) browser.close()
def iex_Rtm_import(): # set download directory path p = { 'download.default_directory': r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\iexRtmFile' } #add options to browser opts.add_experimental_option('prefs', p) browser = Chrome(options=opts) #maximize browser browser.maximize_window() # open the website "https://www.iexindia.com/marketdata/rtm_market_snapshot.aspx" browser.get('https://www.iexindia.com/marketdata/rtm_market_snapshot.aspx') # TEST WAIT UNTIL IN SELENIUM delay = 120 # seconds try: myElem = WebDriverWait(browser, delay).until( EC.presence_of_element_located( (By.ID, 'ctl00_InnerContent_ddlPeriod'))) except TimeoutException: print("Loading took too much time!") # open the dropdown select button "ctl00_InnerContent_ddlPeriod" to select day iexDrpdwnDam = Select( browser.find_elements_by_id("ctl00_InnerContent_ddlPeriod")[0]) # select day element of dropdown by index # "yesterday" iexDrpdwnDam.select_by_index(0) # click on update report buttton "ctl00_InnerContent_btnUpdateReport" browser.find_elements_by_id( "ctl00_InnerContent_btnUpdateReport")[0].click() # updateReport.click() # wait until dropdown is opened dropdownLinks = [] delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until( EC.presence_of_element_located( (By.ID, 'ctl00_InnerContent_reportViewer_ctl05_ctl04_ctl00_ButtonImg' ))) except TimeoutException: print("Loading took too much time!") dropdownLinks = browser.find_elements_by_id( "ctl00_InnerContent_reportViewer_ctl05_ctl04_ctl00_ButtonImg") # click on different download option button "ctl00_InnerContent_reportViewer_ctl05_ctl04_ctl00_ButtonLink" dropdownLinks[0].click() # move all iex files from "C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\iexDamFile" to # "C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\iexDamFile\Archives" srcFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\iexRtmFile' destFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\iexRtmFile\Archives' destFileName = "MarketMinute_" moveFilesToArchive(srcFileLocation, destFileLocation, destFileName) excelLinks = [] delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until( EC.presence_of_element_located((By.LINK_TEXT, 'Excel'))) except TimeoutException: print("Loading took too much time!") excelLinks = browser.find_elements(By.LINK_TEXT, "Excel") excelLinks[0].click() print("iex rtm fetch succesful") time.sleep(15) browser.close()
def wbes_Px_iex_import(): # set download directory path p = {'download.default_directory':r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\wbesPxIexFile'} #add options to browser opts.add_experimental_option('prefs', p) # click on the datepicker select button previousDate = dt.datetime.today() - dt.timedelta(days=1) previousDateFormatted = previousDate.strftime('%d-%m-%Y') # format the date to dd-mm-yyyy month = previousDate.strftime('%B') prevDate = previousDate.strftime('%d') prevDate = int(prevDate) prevDate = str(prevDate) browser = Chrome(options=opts) #maximize browser browser.maximize_window() wbesRtmIexUrl = 'https://wbes.wrldc.in/Report/PXIndex#date={}|revisionno=null|type=5'.format(previousDateFormatted) browser.get(wbesRtmIexUrl) # TEST WAIT UNTIL IN SELENIUM delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.ID, 'newEffectiveDate'))) except TimeoutException: print("Loading took too much time!") # open the calender menu browser.find_elements_by_xpath("//*[@id=\"newEffectiveDate\"]")[0].click() # get the month year from website while(True): t = browser.find_elements_by_xpath("//*[@id=\"ui-datepicker-div\"]/div/div/span[1]") monthString = t[0].text if month == monthString: break else: browser.find_elements_by_xpath("//*[@id=\"ui-datepicker-div\"]/div/a[1]")[0].click() dateString = browser.find_elements_by_xpath("//*[@id=\"ui-datepicker-div\"]/table/tbody/tr/td/a") for t in dateString: if prevDate == t.text: t.click() break delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.ID, 'dwnld'))) except TimeoutException: print("Loading took too much time!") # click on different download option dwnld browser.find_elements_by_id("dwnld")[0].click() srcFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\wbesPxIexFile' destFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\wbesPxIexFile\Archives' revNum = getMaxRTMRevForDate(previousDateFormatted,13) destFileName = "Report-PX_IEX-("+revNum+")-" moveFilesToArchive(srcFileLocation, destFileLocation, destFileName) delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.LINK_TEXT, 'Excel'))) except TimeoutException: print("Loading took too much time!") browser.find_elements(By.LINK_TEXT,"Excel")[0].click() print("wbes PX IEX fetch succesful") time.sleep(10) browser.close() os.chdir(srcFileLocation) for filename in os.listdir(os.getcwd()): if filename.endswith(".xlsx"): y=filename x=filename.replace('('+revNum+')','(0)') os.rename(os.path.join(srcFileLocation, y), os.path.join(srcFileLocation, x))
def iex_Gtam_import(): # set download directory path p = { 'download.default_directory': r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\iexGtamFile' } #add options to browser opts.add_experimental_option('prefs', p) browser = Chrome(options=opts) #maximize browser browser.maximize_window() browser.get('https://www.iexindia.com/marketdata/G-TAM_Details.aspx') # TEST WAIT UNTIL IN SELENIUM delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until( EC.presence_of_element_located( (By.ID, 'ctl00_InnerContent_ddlPeriod'))) except TimeoutException: print("Loading took too much time!") # click on the dropdown button ctl00_InnerContent_ddlPeriod iexDrpdwnDam = Select( browser.find_elements_by_id("ctl00_InnerContent_ddlPeriod")[0]) # select element of dropdown by visible text iexDrpdwnDam.select_by_visible_text('Yesterday') # click on update report ctl00_InnerContent_btnUpdateReport browser.find_elements_by_id( "ctl00_InnerContent_btnUpdateReport")[0].click() # wait until dropdown is opened dropdownLinks = [] delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until( EC.presence_of_element_located( (By.ID, 'ctl00_InnerContent_reportViewer_ctl05_ctl04_ctl00_ButtonLink' ))) except TimeoutException: print("Loading took too much time!") # click on different download option ctl00_InnerContent_reportViewer_ctl05_ctl04_ctl00_ButtonLink browser.find_elements_by_id( "ctl00_InnerContent_reportViewer_ctl05_ctl04_ctl00_ButtonLink" )[0].click() srcFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\iexGtamFile' destFileLocation = r'C:\Users\dheer\Desktop\wrldc\RTM_BROWSER_AUTOMATION\Dumps\iexGtamFile\Archives' destFileName = "DateWiseTrade_" moveFilesToArchive(srcFileLocation, destFileLocation, destFileName) delay = 60 # seconds try: myElem = WebDriverWait(browser, delay).until( EC.presence_of_element_located((By.LINK_TEXT, 'Excel'))) except TimeoutException: print("Loading took too much time!") browser.find_elements(By.LINK_TEXT, "Excel")[0].click() print("iex GTAM fetch succesful") time.sleep(15) browser.close()