Advertisement
Guest User

Untitled

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