def Login(username, pwd): """ Login into the account :param pwd: Password used to login :type pwd: str :param username: Username used to log in :type username: str """ username = str(username) if not username: raise errors.NoUsernameError() with open(ReturnConfigPath(username + '.acc'), 'wb') as f: data = {'username': username, 'password': pwd} Session.post(LOGIN_URL, data=data) # login Session.get(CHECK_URL) if '.ROBLOSECURITY' in Session.cookies: # pickle.dump(Session.cookies, f) pickle.dump(data, f) # Save the username and password now. This way we can automatically login and # support running the bot 24/7 nonstop. Currently the cookie can expire and crash it. print('Save Successful') User._SetLoggedIn(username) return True else: f.close() os.remove(f.name) raise errors.AccountsError()
def SubmitTrade(AmountToTrade, ReceiveAmount, CurrencyToTrade): """ Submit a Trade on ROBLOX :param AmountToTrade: Amount of Tickets or Robux to trade :type AmountToTrade: int :param ReceiveAmount: Amount of Tickets or Robux you want to receive. :type ReceiveAmount: int :param CurrencyToTrade: What currency the AmountToTrade is. :type CurrencyToTrade: str """ # if Fast: # values['ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$OrderType'] = 'MarketOrderRadioButton' state, event = GetValidation(TC_URL) values['__VIEWSTATE'] = state values['__EVENTVALIDATION'] = event values['ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$HaveAmountTextBoxRestyle'] = AmountToTrade values['ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$WantAmountTextBox'] = ReceiveAmount if CurrencyToTrade == "Robux": values['ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$HaveCurrencyDropDownList'] = "Robux" values['ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$WantCurrencyDropDownList'] = "Tickets" else: values['ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$HaveCurrencyDropDownList'] = "Tickets" values['ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$WantCurrencyDropDownList'] = "Robux" Session.post(TC_URL, data=values)
def GetSpread(): """ Get the current spread. :return: The spread. :rtype: int """ tree = html.fromstring(Session.get(TC_URL).text) spread = tree.xpath("//*[@id='CurrencyQuotePane']/div[1]/div[1]/div[4]/text()") return int(spread[0])
def GetRate(): """ Gets the current exchange rates from roblox. :return: Rates: Bux, tix. :rtype: float, float """ tree = html.fromstring(Session.get(TC_URL).text) rate = tree.xpath('//*[@id="CurrencyQuotePane"]/div[1]/div[2]/div[2]/text()') # Rates m = re.split('/', rate[0]) return float(m[0]), float(m[1])
def CheckRates(): """ Checks the current trade rates, in future to modify trades. Unused. """ raise NotImplementedError if t: r = Session.get(TC_URL) tree = html.fromstring(r.text) test = tree.xpath('//*[@id="CurrencyBidsPane"]/div/div[1]/text()') print(test) x = re.split('@', test[0]) x = re.sub("'r\r\n", '', x[0]) x = re.sub('\D', '', x) print(x) return x else: r = Session.get(TC_URL) tree = html.fromstring(r.text) test = tree.xpath('//*[@id="CurrencyOffersPane"]/div/div[1]/span[@class="notranslate"]/text()') print(test[0])
def GetToken(): """ Get X-CSRF-TOKEN for use in sending messages/other activies. :return: The Token :rtype: str """ token = BeautifulSoup(Session.get('http://www.roblox.com/user.aspx').text, "lxml") token = token.find_all(_RbxToken) token = re.findall(r"\((.*)\)", token[0].text)[0] token = re.sub("'", '', token) return token
def LoadAccounts(username): """ Load the specififed account :param username: The account to load :type username: str :return: True if success :rtype: bool """ username = str(username) with open(ReturnConfigPath(username + '.acc'), 'rb') as file: try: # cookies = pickle.load(file) data = pickle.load(file) except EOFError: raise errors.StorageError() # Session.cookies = cookies Session.post(LOGIN_URL, data=data) # For auto login if Session.get(CHECK_URL).url != CHECK_URL: raise errors.AccountsError() User._SetLoggedIn(username) return True
def GetValidation(url): """ gets validation from webpage for submitting requests Works around ROBLOX thingy :param url: Url to look at. :return: Validation. Returns 2 items. """ b = BeautifulSoup(Session.get(url).text, "lxml") viewState = b.findAll("input", {"type": "hidden", "name": "__VIEWSTATE"}) eventValidation = b.findAll('input', {'type': 'hidden', 'name': '__EVENTVALIDATION'}) return viewState[0]['value'], eventValidation[0]['value']
def IsTradeActive(): """ Check for active trades. :return bool: True if trade is active. False otherwise. :rtype: bool """ tree = html.fromstring(Session.get(TC_URL).text) tixT = tree.xpath(('//*[@id="ctl00_ctl00_cphRoblox_cphMyRobloxContent_ctl00_OpenBids_Ope' 'nBidsUpdatePanel"]/div[1][@class="NoResults"]/text()')) buxT = tree.xpath(('//*[@id="ctl00_ctl00_cphRoblox_cphMyRobloxContent_ctl00_OpenOffers_OpenOffersUpdatePanel"]' '/div[1][@class="NoResults"]/text()')) # Default values are ['You do not have any open ____ trades.'] # So [] means there IS a trade if tixT == [] or buxT == []: return True return False
def GetCash(): """ Check how much cash the user has using ROBLOX's API. Requires logged in. :return int: Robux, tickets. :rtype: int, int """ while True: r = Session.get(CURRENCY_URL) try: val = r.json() except JSONDecodeError: DebugLog.debug(r.text) continue break return int(val['robux']), int(val['tickets'])