NeoAccount.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import requests
  2. class NeoAccount:
  3. d = 'http://www.neopets.com'
  4. headers = {
  5. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1951.5 Safari/537.36',
  6. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  7. 'Accept-Language': 'en-us,en;q=0.5',
  8. 'Accept-Encoding': 'gzip, deflate'}
  9. def __init__(self, un, pw, proxy=""):
  10. self.un = un
  11. self.pw = pw
  12. self.proxy = proxy
  13. self.referrer = None
  14. self.result = None
  15. self.session = requests.Session()
  16. a = requests.adapters.HTTPAdapter(max_retries=3)
  17. self.session.mount('http://', a)
  18. self.session.headers = self.headers
  19. if (self.proxy != ""):
  20. self.session.proxies = {'http': 'http://' + self.proxy + '/'}
  21. def get(self, url, referer=''):
  22. if url[0] == '/':
  23. url = self.d + url
  24. if referer != '':
  25. self.result = self.session.get(
  26. url, headers={'Referer': referer}, timeout=20)
  27. else:
  28. self.result = self.session.get(url, timeout=20)
  29. return self.result
  30. def post(self, url, data, referer=''):
  31. if url[0] == '/':
  32. url = self.d + url
  33. if referer != '':
  34. self.result = self.session.post(
  35. url, data=data, headers={'Referer': referer}, timeout=20)
  36. else:
  37. self.result = self.session.post(url, data=data, timeout=20)
  38. return self.result
  39. def login(self):
  40. self.result = self.session.get(
  41. 'http://www.neopets.com/index.phtml', timeout=60)
  42. self.result = self.session.post('http://www.neopets.com/login.phtml',
  43. data={
  44. 'username': self.un,
  45. 'password': self.pw,
  46. 'destination': "http://www.neopets.com/index.phtml"}, timeout=60)
  47. print self.result.url
  48. if 'badpassword' in self.result.url:
  49. return False, 'Bad password'
  50. elif 'hello' in self.result.url:
  51. return False, 'Birthday locked'
  52. elif 'login' in self.result.url:
  53. return False, 'Frozen'
  54. elif 'index' in self.result.url:
  55. return True, 'Logged in'