FRAccount.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # ---------------------------------------------------------------------
  2. # ------------------------- Plight Rising -----------------------------
  3. # -----------------------------txtsd-----------------------------------
  4. # ---------------------------------------------------------------------
  5. """Handles the account, login, and connections"""
  6. # Imports -------------------------------------------------------------
  7. import time
  8. import datetime
  9. import pickle
  10. import re
  11. import os
  12. import sys
  13. import requests
  14. from configobj import ConfigObj
  15. from validate import Validator
  16. # End Imports ---------------------------------------------------------
  17. class FRAccount:
  18. configspec = ConfigObj('config.spec', encoding='UTF8', list_values=False)
  19. config = ConfigObj('config.ini', configspec=configspec)
  20. val = Validator()
  21. test = config.validate(val, preserve_errors=True)
  22. domain = 'http://flightrising.com'
  23. headers = {
  24. 'User-Agent': config['account']['useragent'],
  25. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  26. 'Accept-Language': 'en-us,en;q=0.8',
  27. 'Accept-Encoding': 'gzip,deflate,sdch',
  28. 'DNT': '1' if config['account']['DNT'] else None
  29. }
  30. def __init__(self, un, pw, proxy=""):
  31. self.un = un
  32. self.pw = pw
  33. self.proxy = proxy
  34. self.referrer = None
  35. self.result = None
  36. self.ID = None
  37. self.cookies = None
  38. if os.path.isfile(self.un + '.bin'):
  39. with open(self.un + '.bin', 'rb') as f:
  40. self.session = pickle.load(f)
  41. else:
  42. self.session = requests.Session()
  43. a = requests.adapters.HTTPAdapter(max_retries=0)
  44. self.session.mount('http://', a)
  45. self.session.headers = self.headers
  46. if (self.proxy != ""):
  47. self.session.proxies = {'http': 'http://' + self.proxy + '/'}
  48. def get(self, url, param={}, referer='', head={}):
  49. if url[0] == '/':
  50. url = self.domain + url
  51. if referer != '':
  52. if referer[0] == '/':
  53. referer = self.domain + referer
  54. head['Referer'] = referer
  55. self.result = self.session.get(url, params=param, headers=head, timeout=90)
  56. return self.result
  57. def post(self, url, data={}, param={}, referer='', head={}):
  58. head['Origin'] = 'http://flightrising.com'
  59. if url[0] == '/':
  60. url = self.domain + url
  61. if referer != '':
  62. if referer[0] == '/':
  63. referer = self.domain + referer
  64. head['Referer'] = referer
  65. self.result = self.session.post(url, params=param, data=data, headers=head, timeout=90)
  66. return self.result
  67. def login(self):
  68. try:
  69. self.result = self.session.get('http://www1.flightrising.com/', timeout=90)
  70. if re.search(self.un, self.result.text):
  71. self.result2 = self.session.get('http://flightrising.com/main.php',
  72. params={
  73. 'p': 'hoard',
  74. },
  75. headers={
  76. 'Referer': 'http://www1.flightrising.com/'
  77. },
  78. timeout=90
  79. )
  80. if re.search(self.un, self.result2.text):
  81. # self.ID = self.session.cookies['userid']
  82. self.ID = re.search('clan-profile\/(\d+)">Clan Profile', self.result.text).group(1)
  83. print(
  84. '\n[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Already logged in!')
  85. return True
  86. # print('beforepoop')
  87. token = re.search('"hidden" value="(.+?)"', self.result.text).group(1)
  88. # print('afterpoop')
  89. self.result = self.session.post('https://www1.flightrising.com/login/login',
  90. headers={
  91. # 'Referer': 'http://flightrising.com/main.php?p=coliseum',
  92. 'Referer': 'http://www1.flightrising.com/',
  93. # 'Accept': '*/*',
  94. # 'X-Requested-With': 'XMLHttpRequest',
  95. 'X-Request-Id': None,
  96. # 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  97. 'Origin': 'http://www1.flightrising.com',
  98. 'Cache-Control': 'max-age=0'
  99. },
  100. data={
  101. '_token': token,
  102. 'uname': self.un,
  103. 'remember': '1',
  104. 'pword': self.pw,
  105. # 'dologin': 'Login'
  106. },
  107. timeout=90
  108. )
  109. # self.result2 = self.session.get('http://flightrising.com/main.php?p=coliseum',
  110. # headers={
  111. # 'Referer': 'http://flightrising.com/main.php?p=coliseum'
  112. # },
  113. # timeout=90
  114. # )
  115. # print(self.result.url)
  116. # if re.search('Logging in...', self.result.text):
  117. if re.search('badpw=true', self.result.url):
  118. print('\n[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad Password Error.')
  119. return False
  120. if re.search('maint=true', self.result.url):
  121. print('\n[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Maintenance Error.')
  122. return False
  123. if re.search(self.un, self.result.text):
  124. # self.ID = self.result.cookies['userid']
  125. self.ID = re.search('clan-profile\/(\d+)">Clan Profile', self.result.text).group(1)
  126. print('\n[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Logged in!')
  127. if os.path.isfile(self.un + '.bin'):
  128. os.remove(self.un + '.bin')
  129. with open(self.un + '.bin', 'wb') as f:
  130. pickle.dump(self.session, f, pickle.HIGHEST_PROTOCOL)
  131. return True
  132. else:
  133. print(
  134. '\n[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Authorization Error.')
  135. return False
  136. except Exception as e:
  137. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Network Error.')
  138. print(type(e))
  139. print(e.args)
  140. print(e)
  141. time.sleep(10)
  142. def getID(self):
  143. return self.ID