Advertisement
SaucySome

Untitled

May 13th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. import requests
  2. import time
  3. import sys
  4. import os
  5. os.system("color oc")
  6.  
  7. class RobloxBot:
  8.     """A simple Roblox bot class"""
  9.     def __init__(self, group_id):
  10.         # creates a session
  11.         self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'}
  12.         self.session = requests.session()
  13.         self.session.headers.update(self.headers)
  14.         # sets group id
  15.         self.group_id = group_id
  16.         # checks if program is able to connect
  17.         if requests.get('https://pastebin.com/raw/iRDJv57z').text != 'OK':
  18.             sys.exit('Unable to connect')
  19.  
  20.     def login(self, username, password):
  21.         print('Logging In...')
  22.         # logs into Roblox with the provided username and password
  23.         payload = {'username': username, 'password': password}
  24.         self.session.post('https://www.roblox.com/newlogin', data=payload)
  25.         print('Successfully Logged In.')
  26.  
  27.     def get_shirts(self, starting_page=66, category='12', wait=10):
  28.         page_num = starting_page
  29.         while page_num < 999999:
  30.             # gets asset ids of shirts
  31.             params = {'CatalogContext': 66, 'Subcategory': category, 'SortAggregation': '5', 'LegendExpanded': 'true', 'Category': '3', 'PageNumber': page_num}
  32.             try:
  33.                 r = self.session.get('https://www.roblox.com/catalog/json', params=params)
  34.                 r.raise_for_status()
  35.             except requests.exceptions.HTTPError:
  36.                 print('Status Error: {}'.format(r.status_code))
  37.                 time.sleep(30)
  38.                 continue
  39.             print('Got items from page: {}'.format(page_num))
  40.             # iterates through json and grabs asset ids from page
  41.             for asset in r.json():
  42.                 # calls download with the asset id
  43.                 while True:
  44.                     try:
  45.                         self.__download(asset['AssetId'])
  46.                         break
  47.                     except:
  48.                         print('Found an error. Retrying.')
  49.                         continue
  50.                 time.sleep(wait)
  51.             page_num += 1
  52.  
  53.     def __download(self, assetId):
  54.         # gets name, description, price and file
  55.         data = self.session.get('https://api.roblox.com/Marketplace/ProductInfo', params={'assetId': assetId}).json()
  56.         name, description, price, asset_type = data['Name'], data['Description'], data['PriceInRobux'], data['AssetTypeId']
  57.         # gets templates asset id
  58.         count = 0
  59.         while count < 10:
  60.             assetId -= 1
  61.             try:
  62.                 r = self.session.get('https://api.roblox.com/Marketplace/ProductInfo', params={'assetId': assetId})
  63.                 count += 1
  64.                 r.raise_for_status()
  65.                 if r.json()['Name'] == name:
  66.                     print('Got template id for: {}'.format(assetId))
  67.                     break
  68.             except (requests.exceptions.HTTPError, ValueError):
  69.                 print('Could not find template for: {}'.format(assetId))
  70.                 return
  71.         else:
  72.             print('Could not find template for: {}'.format(assetId))
  73.             return
  74.         # downloads file to memory for later upload
  75.         file = self.session.get('https://www.roblox.com/asset/', params={'id': assetId})
  76.         print('Downloaded Template.')
  77.         self.__upload(name, description, price, file, asset_type, assetId)
  78.  
  79.     def __upload(self, name, description, price, file, asset_type, assetId):
  80.         # gets verification token
  81.         r = self.session.get('https://www.roblox.com/build/upload')
  82.         token = r.text.split('name=__RequestVerificationToken type=hidden value=')[-1].split('>')[0]
  83.         print('Got Request Verification Token.')
  84.         # uploads file to Roblox
  85.         data = {'file': ('template.png', file.content, 'image/png')}
  86.         payload = {'__RequestVerificationToken': token, 'assetTypeId': asset_type, 'isOggUploadEnabled': 'True', 'isTgaUploadEnabled': 'True', 'groupId': self.group_id, 'onVerificationPage': 'False', 'name': name}
  87.         r = self.session.post('https://www.roblox.com/build/upload', files=data, data=payload)
  88.         # gets asset id so the shirt can be published
  89.         asset_id = r.text.split('uploadedAssetId=')[-1].split('" />')[0]
  90.         assets = {'id': asset_id}
  91.         # gets required fields for post request
  92.         r = self.session.get('https://www.roblox.com/my/item.aspx', params=assets)
  93.         view_state = r.text.split('id="__VIEWSTATE" value="')[-1].split('" />')[0]
  94.         view_gen = r.text.split('id="__VIEWSTATEGENERATOR" value="')[-1].split('" />')[0]
  95.         validation = r.text.split('id="__EVENTVALIDATION" value="')[-1].split('" />')[0]
  96.         # creates payload for shirt editing/publishing
  97.         payload = {'__EVENTTARGET': 'ctl00$cphRoblox$SubmitButtonBottom', '__EVENTARGUMENT': '', '__VIEWSTATE': view_state, '__VIEWSTATEGENERATOR': view_gen, '__EVENTVALIDATION': validation, 'ctl00$cphRoblox$NameTextBox': name, 'ctl00$cphRoblox$DescriptionTextBox': description, 'ctl00$cphRoblox$SellThisItemCheckBox': 'on', 'ctl00$cphRoblox$SellForRobux': 'on', 'ctl00$cphRoblox$RobuxPrice': price, 'ctl00$cphRoblox$EnableCommentsCheckBox': 'on', 'GenreButtons2': '1', 'ctl00$cphRoblox$actualGenreSelection': '1'}
  98.         self.session.post('https://www.roblox.com/my/item.aspx', params=assets, data=payload)
  99.         print('Successfully Uploaded: {}'.format(assetId))
  100.  
  101. if __name__ == '__main__':
  102.     # instantiates RobloxBot
  103.     bot = RobloxBot(group_id='GROUP ID')
  104.     # logs into Roblox
  105.     bot.login(username='USERNAME', password='PASSWORD')
  106.     # starts collecting shirts on page one with a wait time of 10 seconds
  107.     bot.get_shirts(starting_page=100, category='12', wait=3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement