import requests import time import sys import os os.system("color oc")   class RobloxBot:     """A simple Roblox bot class"""     def __init__(self, group_id):         # creates a session         self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'}         self.session = requests.session()         self.session.headers.update(self.headers)         # sets group id         self.group_id = group_id         # checks if program is able to connect         if requests.get('https://pastebin.com/raw/iRDJv57z').text != 'OK':             sys.exit('Unable to connect')       def login(self, username, password):         print('Logging In...')         # logs into Roblox with the provided username and password         payload = {'username': username, 'password': password}         self.session.post('https://www.roblox.com/newlogin', data=payload)         print('Successfully Logged In.')       def get_shirts(self, starting_page=66, category='12', wait=10):         page_num = starting_page         while page_num < 999999:             # gets asset ids of shirts             params = {'CatalogContext': 66, 'Subcategory': category, 'SortAggregation': '5', 'LegendExpanded': 'true', 'Category': '3', 'PageNumber': page_num}             try:                 r = self.session.get('https://www.roblox.com/catalog/json', params=params)                 r.raise_for_status()             except requests.exceptions.HTTPError:                 print('Status Error: {}'.format(r.status_code))                 time.sleep(30)                 continue             print('Got items from page: {}'.format(page_num))             # iterates through json and grabs asset ids from page             for asset in r.json():                 # calls download with the asset id                 while True:                     try:                         self.__download(asset['AssetId'])                         break                     except:                         print('Found an error. Retrying.')                         continue                 time.sleep(wait)             page_num += 1       def __download(self, assetId):         # gets name, description, price and file         data = self.session.get('https://api.roblox.com/Marketplace/ProductInfo', params={'assetId': assetId}).json()         name, description, price, asset_type = data['Name'], data['Description'], data['PriceInRobux'], data['AssetTypeId']         # gets templates asset id         count = 0         while count < 10:             assetId -= 1             try:                 r = self.session.get('https://api.roblox.com/Marketplace/ProductInfo', params={'assetId': assetId})                 count += 1                 r.raise_for_status()                 if r.json()['Name'] == name:                     print('Got template id for: {}'.format(assetId))                     break             except (requests.exceptions.HTTPError, ValueError):                 print('Could not find template for: {}'.format(assetId))                 return         else:             print('Could not find template for: {}'.format(assetId))             return         # downloads file to memory for later upload         file = self.session.get('https://www.roblox.com/asset/', params={'id': assetId})         print('Downloaded Template.')         self.__upload(name, description, price, file, asset_type, assetId)       def __upload(self, name, description, price, file, asset_type, assetId):         # gets verification token         r = self.session.get('https://www.roblox.com/build/upload')         token = r.text.split('name=__RequestVerificationToken type=hidden value=')[-1].split('>')[0]         print('Got Request Verification Token.')         # uploads file to Roblox         data = {'file': ('template.png', file.content, 'image/png')}         payload = {'__RequestVerificationToken': token, 'assetTypeId': asset_type, 'isOggUploadEnabled': 'True', 'isTgaUploadEnabled': 'True', 'groupId': self.group_id, 'onVerificationPage': 'False', 'name': name}         r = self.session.post('https://www.roblox.com/build/upload', files=data, data=payload)         # gets asset id so the shirt can be published         asset_id = r.text.split('uploadedAssetId=')[-1].split('" />')[0]         assets = {'id': asset_id}         # gets required fields for post request         r = self.session.get('https://www.roblox.com/my/item.aspx', params=assets)         view_state = r.text.split('id="__VIEWSTATE" value="')[-1].split('" />')[0]         view_gen = r.text.split('id="__VIEWSTATEGENERATOR" value="')[-1].split('" />')[0]         validation = r.text.split('id="__EVENTVALIDATION" value="')[-1].split('" />')[0]         # creates payload for shirt editing/publishing         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'}         self.session.post('https://www.roblox.com/my/item.aspx', params=assets, data=payload)         print('Successfully Uploaded: {}'.format(assetId))   if __name__ == '__main__':     # instantiates RobloxBot     bot = RobloxBot(group_id='GROUP ID')     # logs into Roblox     bot.login(username='USERNAME', password='PASSWORD')     # starts collecting shirts on page one with a wait time of 10 seconds     bot.get_shirts(starting_page=100, category='12', wait=3)