slacky Posted May 15, 2013 Share Posted May 15, 2013 (edited) Partially possible. SCAR does not allow for form manipulation. So the only way to log in would be to move the mouse and log in. Requiring you to store username and password in the script, type it in when needed at the correct position (x,y). ^ That will not be very flexible, if you resize the browser, you would need to change the login-box coordinates in scar as well (that sucks)... You should consider Python (the language) for this - Python is very suited for such tasks. A quick and dirty example in Python, could be made a LOT shorter, but it's based on the code you already have, so it's not very pythonic: # -*- coding: utf-8 -*-import mechanizeimport reimport time#username and passname = 'blabla'pwd = 's0meP4ss'#Browserclass Exchange: def __init__(self, user, pwd): self.br = mechanize.Browser() self.br_trading = mechanize.Browser() self.name = user self.pwd = pwd def login_in(self): ''' #login to website ''' self.br_trading.open("http://mtgox.com") self.br_trading.select_form(nr=1) self.br_trading["user_session[username]"] = self.name self.br_trading["user_session[password]"] = self.pwd self.br_trading.submit() print "logged in, and ready to sell and by!" def buy(self, amount, price_per_btc): ''' #buy x stocks for y price at n website ''' # self.br_trading.open("http://mtgox.com/some_url_to_buy_btc.html") # self.br_trading.select_form(nr=0) #form number (see html source of site) # self.br_trading["user_session[price]"] = price # self.br_trading["user_session[amount]"] = amount # self.br_trading.submit() print "Not implementetd (don't have an accound to test)" def sell(self, amount, price_per_btc): ''' this is similar to the above given example, but we sell now! ''' print "Not implementetd (don't have an accound to test)" def rate(self, currency): ''' # Get current exchangerate ''' while 1: data = self.br.open("http://bitcoincharts.com/markets/mtgox%s.html" % currency) html = data.read() pattern = '<label>Last Trade</label><span>(.*?)</span>' match = re.findall(pattern, html) if match: break; return float(match[0]) def currency_rate(self, amount, fromCurrency, toCurrency): while 1: data = self.br.open("http://www.x-rates.com/calculator/?from=%s&to=%s&amound=%s" % (fromCurrency, toCurrency, amount)) html = data.read() pattern = '<span class="ccOutputRslt">(.*?)<span class="ccOutputTrail">' match = re.findall(pattern, html) res = float(match[0]) if match: pattern2 = '<span class="ccOutputTrail">(.*?)</span><span class="ccOutputCode">' match2 = re.findall(pattern2, html) if match2: res = float(match[0] + match2[0]) if res: break return resif __name__ == '__main__': exc = Exchange('userName', 'p4ssw0rD') a = exc.rate('EUR') c_rate = exc.currency_rate(1, 'EUR', 'USD') value = c_rate*a btc_usd_val = exc.rate('USD'); delta = btc_usd_val - value #Fees. Skal være mindre end `e`. fee = (1/0.994) * (btc_usd_val - (0.994 * btc_usd_val)) if (delta > fee): print(fee) print 'w00p w00p!' exc.login_in() exc.buy(10, 115) else: print 'bedre lykke neste gang..' time.sleep(1800) #no luck? wait half an hour (or should we sell at this point?). you could probably be able to sell and buy with only a few more lines, so it's pretty simple. Edited May 16, 2013 by slacky Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 16, 2013 Author Share Posted May 16, 2013 Okay, so you are saying that Scar is not suitable for this type of programming? Well maybe I am on the wrong forum then My problem is just that im totally lost in Python (BTW, i like your comments in your script ) Quote Link to comment Share on other sites More sharing options...
slacky Posted May 17, 2013 Share Posted May 17, 2013 Yes, that is correct. Most programming languages are similar in a sense, so it does not take much time to grasp python if you know some other language. My example is not the simplest to understand, as I am using a class, and a global name "self", which refers to "this class". I often see some danish people on "www.diskusjon.no", and they got a good Python section (Scriptingspråk (Python, Perl, Ruby o.l.) - Forum - Hardware.no), and a lot of great programmers! So it's worth a try if you are in the mood! :-) Quote Link to comment Share on other sites More sharing options...