Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. import requests
  2. from hashlib import md5
  3. from time import sleep, time
  4.  
  5. '''
  6. TODO:
  7. Login [x]
  8. Register
  9. Thanks
  10. Shoutbox
  11. '''
  12.  
  13. class Account:
  14.  
  15.     logged_in = False
  16.     username = ''
  17.     profile_id = None
  18.  
  19.     def md5(self, string):
  20.         m = md5()
  21.         m.update(string.encode('utf-8'))
  22.         return m.hexdigest()
  23.  
  24.     def login(self, username, password):
  25.         try:
  26.             self.session = requests.Session()
  27.             r = self.session.get('http://www.gta-sarp.com/forums', timeout=10)
  28.             self.cookie = r.headers['Set-Cookie']
  29.  
  30.             self.username = username
  31.             self.password = self.md5(password)
  32.  
  33.             self.headers = {
  34.                 'Set-Cookie':self.cookie, # Uses the cookie from the above get request
  35.                 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36', }
  36.  
  37.             data = {
  38.                 'vb_login_username':self.username,
  39.                 'vb_login_password': '',
  40.                 'vb_login_password_hint':'Password',
  41.                 'securitytoken':'guest',
  42.                 'do':'login',
  43.                 'vb_login_md5password':self.password,
  44.                 'vb_login_md5password_utf':self.password
  45.             }
  46.  
  47.             r = self.session.post('http://www.gta-sarp.com/forums/login.php', headers=self.headers, data=data)
  48.  
  49.             if('Redirecting...' in r.text):
  50.                 self.logged_in = True
  51.                 print('Successfully logged into: {}'.format(username))
  52.                 sleep(2)
  53.                 r = self.session.get('http://www.gta-sarp.com/forums/')
  54.             else:
  55.                 print('Invalid username or password')
  56.         except:
  57.             return 'Could not connect to host.'
  58.  
  59.     def shout(self, message): # Not working yet.
  60.         if not(self.logged_in): return print('You must be logged in to shout.')
  61.         if(self.profile_id == None): return print('You must set your profile ID with the code "account.profile_id = [ID HERE]" to use this feature.')
  62.  
  63.         data = {
  64.             'bb_userid':self.profile_id,
  65.             'do':'ajax',
  66.             'message':message,
  67.             'bb_password':self.password,
  68.             'tabid':'shouts',
  69.             'pmtime':int(time()),
  70.             'action':'save'
  71.         }
  72.  
  73.         self.session.post('http://www.gta-sarp.com/forums/vbshout.php', headers=self.headers, data=data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement