Advertisement
Guest User

Untitled

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