Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated code for stockpair.com

  • Loading branch information...
commit f0a15b2da3b3a609895e65a7226a05c3c122ef4b 1 parent ef8c4d8
@bappybd authored
Showing with 381 additions and 31 deletions.
  1. +185 −0 application_log.txt
  2. +16 −31 main.py
  3. +180 −0 main2.py
View
185 application_log.txt
@@ -0,0 +1,185 @@
+2013-03-13 23:55 main result table found
+2013-03-13 23:55 shot term tab clicked
+2013-03-13 23:55 60 seconds button clicked
+2013-03-13 23:55 asset row Euro-Dollar found
+2013-03-13 23:55 textOptionView found
+2013-03-13 23:55 price found: 1.29681
+2013-03-13 23:55 High asset value clicked
+2013-03-13 23:55 Your selection input field found
+2013-03-13 23:55 login popupbox found
+2013-03-13 23:55 Username input field found
+2013-03-13 23:55 Password input field found
+2013-03-13 23:55 LoginButton found
+2013-03-13 23:55 Buy button clicked
+2013-03-16 16:07 Currency tab ckicked
+2013-03-16 16:07 Currency Link EUR/USD ckicked
+2013-03-16 16:24 Currency tab clicked
+2013-03-16 16:24 Currency Link EUR/USD ckicked
+2013-03-16 22:01 Currency tab clicked
+2013-03-16 22:01 Currency Link EUR/USD ckicked
+2013-03-16 22:19 Currency tab clicked
+2013-03-16 22:19 Currency Link EUR/USD ckicked
+2013-03-16 22:21 Currency tab clicked
+2013-03-16 22:21 Currency Link EUR/USD clicked
+2013-03-16 22:22 Currency tab clicked
+2013-03-16 22:22 Currency Link EUR/USD clicked
+2013-03-16 22:22 Expiry selectbox found
+2013-03-16 22:23 Currency tab clicked
+2013-03-16 22:23 Currency Link EUR/USD clicked
+2013-03-16 22:23 Expiry selectbox found
+2013-03-16 22:26 Currency tab clicked
+2013-03-16 22:26 Currency Link EUR/USD clicked
+2013-03-16 22:26 Expiry selectbox found
+2013-03-16 23:03 Currency tab clicked
+2013-03-16 23:03 Currency Link EUR/USD clicked
+2013-03-16 23:03 Expiry selectbox found
+2013-03-16 23:04 Currency tab clicked
+2013-03-16 23:04 Currency Link EUR/USD clicked
+2013-03-16 23:05 Expiry selectbox found
+2013-03-16 23:06 Currency tab clicked
+2013-03-16 23:06 Currency Link EUR/USD clicked
+2013-03-16 23:06 Expiry selectbox found
+2013-03-16 23:08 Currency tab clicked
+2013-03-16 23:08 Currency Link EUR/USD clicked
+2013-03-16 23:08 Expiry selectbox found
+2013-03-16 23:08 Option 5 clicked
+2013-03-16 23:09 Currency tab clicked
+2013-03-16 23:09 Currency Link EUR/USD clicked
+2013-03-16 23:09 Expiry selectbox found
+2013-03-16 23:09 Option 5 clicked
+2013-03-16 23:23
+
+************************Started new session*************************
+2013-03-16 23:25 Currency tab clicked
+2013-03-16 23:25 Currency Link EUR/USD clicked
+2013-03-16 23:25 Expiry selectbox found
+2013-03-16 23:25 Option 5 clicked
+2013-03-16 23:27
+
+************************Started new session (2013-03-16 23:27)*************************
+2013-03-16 23:28 Currency tab clicked
+2013-03-16 23:28 Currency Link EUR/USD clicked
+2013-03-16 23:28 Expiry selectbox found
+2013-03-16 23:28 Option 5 clicked
+2013-03-17 01:17
+
+************************Started new session (2013-03-17 01:17)*************************
+2013-03-17 01:19 Currency tab clicked
+2013-03-17 01:19 Currency Link EUR/USD clicked
+2013-03-17 01:19 Expiry selectbox found
+2013-03-17 01:19 Option 5 clicked
+2013-03-17 01:26
+
+*******************Started new session (2013-03-17 01:26)********************
+2013-03-17 01:27 Currency tab clicked
+2013-03-17 01:27 Currency Link EUR/USD clicked
+2013-03-17 01:27 Expiry selectbox found
+2013-03-17 01:27 Option 5 clicked
+2013-03-17 13:56
+
+*******************Started new session (2013-03-17 13:56)********************
+2013-03-17 13:57 Currency tab clicked
+2013-03-17 13:57 Currency Link EUR/USD clicked
+2013-03-17 13:57 Expiry selectbox found
+2013-03-17 13:57 Option 5 clicked
+2013-03-17 14:00
+
+*******************Starting new session (2013-03-17 14:00)********************
+2013-03-17 14:00 Popup Tutorial box closed
+2013-03-17 14:00 Currency tab clicked
+2013-03-17 14:00 Currency Link EUR/USD clicked
+2013-03-17 14:00 Expiry selectbox found
+2013-03-17 14:00 Option 5 clicked
+2013-03-17 14:04
+
+*******************Starting new session (2013-03-17 14:04)********************
+2013-03-17 14:04 Popup Tutorial box closed
+2013-03-17 14:04 Currency tab clicked
+2013-03-17 14:04 Currency Link EUR/USD clicked
+2013-03-17 14:04 Expiry selectbox found
+2013-03-17 14:04 Option 5 clicked
+2013-03-17 14:06
+
+*******************Starting new session (2013-03-17 14:06)********************
+2013-03-17 14:06 Popup Tutorial box closed
+2013-03-17 14:06 Currency tab clicked
+2013-03-17 14:06 Currency Link EUR/USD clicked
+2013-03-17 14:06 Expiry selectbox found
+2013-03-17 14:06 Option 5 clicked
+2013-03-17 14:16
+
+*******************Starting new session (2013-03-17 14:16)********************
+2013-03-17 14:18 Popup Tutorial box closed
+2013-03-17 14:18 Currency tab clicked
+2013-03-17 14:18 Currency Link EUR/USD clicked
+2013-03-17 14:18 Expiry selectbox found
+2013-03-17 14:18 Option 5 selected
+2013-03-17 14:18 Trade amount 30 selected
+2013-03-17 14:34
+
+*******************Starting new session (2013-03-17 14:34)********************
+2013-03-17 14:34 Popup Tutorial box closed
+2013-03-17 14:34 Currency tab clicked
+2013-03-17 14:34 Currency Link EUR/USD clicked
+2013-03-17 14:34 Expiry selectbox found
+2013-03-17 14:34 Option 5 selected
+2013-03-17 14:34 Trade amount 30 selected
+2013-03-17 15:27
+
+*******************Starting new session (2013-03-17 15:27)********************
+2013-03-17 15:28 Popup Tutorial box closed
+2013-03-17 15:28 Currency tab clicked
+2013-03-17 15:28 Currency Link EUR/USD clicked
+2013-03-17 15:28 Call clicked
+2013-03-17 15:28 Expiry selectbox found
+2013-03-17 15:28 Option 5 selected
+2013-03-17 15:28 Trade amount 30 selected
+2013-03-17 18:27
+
+*******************Starting new session (2013-03-17 18:27)********************
+2013-03-17 18:27
+
+*******************Starting new session (2013-03-17 18:27)********************
+2013-03-17 18:28
+
+*******************Starting new session (2013-03-17 18:28)********************
+2013-03-17 18:29 username entered
+2013-03-17 18:29 username password
+2013-03-17 18:29 login button clicked
+2013-03-17 18:32
+
+*******************Starting new session (2013-03-17 18:32)********************
+2013-03-17 18:32 username entered
+2013-03-17 18:32 username password
+2013-03-17 18:32 login button clicked
+2013-03-17 18:34
+
+*******************Starting new session (2013-03-17 18:34)********************
+2013-03-17 18:34 username entered
+2013-03-17 18:34 password entered
+2013-03-17 18:34 login button clicked
+2013-03-17 18:35
+
+*******************Starting new session (2013-03-17 18:35)********************
+2013-03-17 18:36 username entered
+2013-03-17 18:36 password entered
+2013-03-17 18:36 login button clicked
+2013-03-17 18:37 Currency tab clicked
+2013-03-17 18:37 Currency Link EUR/USD clicked
+2013-03-17 18:37 Call clicked
+2013-03-17 18:37 Expiry selectbox found
+2013-03-17 18:37 Option 5 selected
+2013-03-17 18:37 Trade amount 30 Min selected
+2013-03-17 18:41
+
+*******************Starting new session (2013-03-17 18:41)********************
+2013-03-17 18:41 username entered
+2013-03-17 18:41 password entered
+2013-03-17 18:41 login button clicked
+2013-03-17 18:41 Popup Tutorial box closed
+2013-03-17 18:41 Currency tab clicked
+2013-03-17 18:41 Currency Link EUR/USD clicked
+2013-03-17 18:41 Call clicked
+2013-03-17 18:41 Expiry selectbox found
+2013-03-17 18:41 Option 5 selected
+2013-03-17 18:41 Trade amount 30 Min selected
View
47 main.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import os, time, datetime
-#from pyvirtualdisplay import Display
+from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
@@ -10,15 +10,15 @@ class seleniumApp:
def __init__( self ):
#site specific variables
self.url = 'https://www.24option.com/24option/#Trade'
- self.asset = 'EUR/USD'
+ self.assetTitle = 'Euro-Dollar'
self.assetXtraContent = ' <span class="optionRow_asset_description_HiLo">&nbsp;</span>'
self.assetDirection = 'High'
self.username = 'pacificcoder';
self.password = 'go4succeSS'
- self.pageSaveDir = 'pages/'
self.logfile = 'application_log.txt'
self.max_waiting_time = 5
+ # Enable display for server (No monitor)
#display = Display(visible=0, size=(1024, 768))
#display.start()
@@ -51,12 +51,11 @@ def startScrap(self):
self.log("60 seconds button clicked")
time.sleep(2)
- #elemAsset = self.getElementByXpath('//table[@class="optionRow_layout"]//tr//td[@class="optionRow_asset"]//div[text()="'+self.asset+'"][1]' )
- elemAsset = self.getElementByXpath('//table[@class="optionRow_layout"]//tr//td[@class="optionRow_asset"]//div[@title="Euro-Dollar"][1]' )
+ elemAsset = self.getElementByXpath('//table[@class="optionRow_layout"]//tr//td[@class="optionRow_asset"]//div[@title="'+self.assetTitle+'"][1]' )
if(elemAsset):
- self.log("asset row found")
- self.log(elemAsset.text)
+ self.log("asset row "+self.assetTitle+" found")
+ #self.log(elemAsset.text)
elemAsset.click()
time.sleep(.5)
@@ -148,39 +147,25 @@ def getElementByXpath(self, regex, waitForElement = False):
#application log
def log(self, contents):
+ logFileName = self.logfile
+
#output to console
print contents + "\n"
- logFileName = self.logfile
-
#fix contents
- now = datetime.datetime.now()
- currentDateTime = now.strftime("%Y-%m-%d %H:%M")
+ currentDateTime = self.getCurrentDateTime()
contents = currentDateTime + " " + str(contents) + "\n"
with open(logFileName, "a") as f:
f.write(contents)
+
+ def getCurrentDateTime(self) :
+ now = datetime.datetime.now()
+ currentDateTime = now.strftime("%Y-%m-%d %H:%M")
+
+ return currentDateTime
#create application
if __name__ == "__main__":
scrapper = seleniumApp()
- scrapper.startScrap()
-
-
-
-
-
-
-
-#class Login(unittest.TestCase):
-# def setUp(self):
-# self.driver = webdriver.Firefox()
-#
-# def tearDown(self):
-# self.driver.quit()
-#
-# def test_login(self):
-# driver = self.driver
-# driver.get('http://testurl')
-# username = driver.find_element_by_name('user_id')
-# username.send_keys('admin')
+ scrapper.startScrap()
View
180 main2.py
@@ -0,0 +1,180 @@
+#!/usr/bin/env python
+
+import os, time, datetime
+from pyvirtualdisplay import Display
+from selenium import webdriver
+from selenium.common.exceptions import NoSuchElementException
+from selenium.webdriver.common.keys import Keys
+
+class seleniumApp:
+ def __init__( self ):
+
+ self.max_waiting_time = 5
+ self.max_webelement_retry = 3
+
+ #site specific variables
+ self.url = 'https://www.stockpair.com/sp#trading/page'
+ self.loginUrl = 'http://www.stockpair.com/sp#session/loginpage?email='
+ self.currencyTitle = 'EUR/USD'
+ self.expiryTime = 5
+ self.expiryType = "Min"
+ self.exType = ""
+ self.assetDirection = 'Call'
+ self.tradeAmount = 30
+ self.username = 'shaiful1984@gmail.com';
+ self.password = 'go4succeSS'
+ self.logfile = 'application_log.txt'
+
+ # Enable display for server (No monitor)
+ #display = Display(visible=0, size=(1024, 768))
+ #display.start()
+
+ #init Selenium Webdriver
+ self.driver = webdriver.Firefox()
+ #self.driver = webdriver.Chrome()
+
+ # Start logging
+ self.log("\n\n*******************Starting new session ("+str(self.getCurrentDateTime())+")********************")
+
+ def startScrap(self):
+ driver = self.driver
+ #driver.get(self.url)
+
+ # login first
+ self.login()
+
+ try:
+ #time.sleep(self.max_waiting_time)
+
+ # close the popup tutorial
+ elemTutorialCloseButton = self.getElementByXpath("//div[@class='tutorial']//div[@class='closeButton']")
+ if(elemTutorialCloseButton):
+ elemTutorialCloseButton.click()
+ self.log("Popup Tutorial box closed")
+
+ # Click Currency Tab
+ elemCurrencyTab = self.getElementByXpath("//div[@id='pairGroup8']", True)
+ if(elemCurrencyTab):
+ elemCurrencyTab.click()
+ self.log("Currency tab clicked")
+
+ # Click on currency link
+ elemCurrencyLink = self.getElementByXpath("//div[@id='pairSelect111']//a[text()='"+self.currencyTitle+"']", True)
+ if(elemCurrencyLink):
+ elemCurrencyLink.click()
+ self.log("Currency Link "+self.currencyTitle+" clicked")
+ time.sleep(1)
+
+ # Click "Call" / "Put" button
+ if(self.assetDirection == 'Call'):
+ elemCallPutButton = self.getElementByXpath("//table[@class='selectionStrip']//tbody//tr[1]//td[1]//div[2]//div[2]", True)
+ else:
+ elemCallPutButton = self.getElementByXpath("//table[@class='selectionStrip']//tbody//tr[1]//td[3]//div[2]//div[2]", True)
+ if(elemCallPutButton):
+ elemCallPutButton.click()
+ self.log(str(self.assetDirection)+" clicked")
+ time.sleep(1)
+
+
+ # Select expiry combobox
+ #b.find_element_by_xpath("//select/option[@value='The Options I am Looking for']").click()
+ elemExpiryCombo = self.getElementByXpath("//div[@class='selectInterval']//div[2]//div[1]//select[1]")
+ if(elemExpiryCombo):
+ self.log("Expiry selectbox found ")
+
+ if self.expiryType == 'Min':
+ self.exType = 'Minutes'
+ else:
+ self.exType = 'Days'
+
+ for option in elemExpiryCombo.find_elements_by_tag_name('option'):
+ if option.text == 'In the next '+str(self.expiryTime)+' '+self.exType:
+ option.click()
+ self.log('Option '+str(self.expiryTime)+' selected')
+ time.sleep(1)
+
+ # select amount to trade
+ elemAmountTradeSelectbox = self.getElementByXpath("//select[@name='amountSelect']//option[text()='"+str(self.tradeAmount)+"']")
+ if(elemAmountTradeSelectbox):
+ elemAmountTradeSelectbox.click()
+ self.log('Trade amount '+str(self.tradeAmount)+' '+str(self.expiryType)+' selected ')
+
+ time.sleep(3)
+
+ except NoSuchElementException:
+ print "An error occured"
+
+ # close the browser
+ driver.quit()
+
+ def login(self):
+ self.driver.get(self.loginUrl)
+
+ # add username
+ elemUsername = self.getElementByXpath("//div[@class='formSection']//span[1]//input[@name='email']", True)
+ if(elemUsername):
+ self.log("username entered ")
+ elemUsername.send_keys(self.username)
+
+ # add password
+ elemPassword = self.getElementByXpath("//div[@class='formSection']//span[1]//input[@name='password']")
+ if(elemPassword):
+ self.log("password entered")
+ elemPassword.send_keys(self.password)
+
+ # login button
+ elemLoginButton = self.getElementByXpath("//div[@class='formSection']//span[1]//input[@type='submit']")
+ if(elemLoginButton):
+ elemLoginButton.click()
+ self.log("login button clicked ")
+
+ time.sleep(3)
+
+ #get element
+ def getElementByXpath(self, regex, waitForElement = False):
+
+ retryCount = 0
+
+ # new code
+ while retryCount <= self.max_webelement_retry:
+ try:
+ elem = self.driver.find_element_by_xpath(regex) # Find the query box
+ if(elem):
+ return elem
+ break
+ else:
+ time.sleep(self.max_waiting_time)
+
+ if(waitForElement):
+ print "waiting for element to load..."
+ retryCount = retryCount + 1
+
+ except NoSuchElementException:
+ time.sleep(self.max_waiting_time)
+ print "waiting for element to load.."
+ retryCount = retryCount + 1
+
+ #application log
+ def log(self, contents):
+ logFileName = self.logfile
+
+ #output to console
+ print contents + "\n"
+
+ #fix contents
+ currentDateTime = self.getCurrentDateTime()
+ contents = currentDateTime + " " + str(contents) + "\n"
+
+ with open(logFileName, "a") as f:
+ f.write(contents)
+
+ def getCurrentDateTime(self) :
+ now = datetime.datetime.now()
+ currentDateTime = now.strftime("%Y-%m-%d %H:%M")
+
+ return currentDateTime
+
+#create application
+if __name__ == "__main__":
+ scrapper = seleniumApp()
+ scrapper.startScrap()
Please sign in to comment.
Something went wrong with that request. Please try again.