Familiar.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. # ---------------------------------------------------------------------
  2. # ------------------------- Plight Rising -----------------------------
  3. # -----------------------------txtsd-----------------------------------
  4. # ---------------------------------------------------------------------
  5. """Bonds with all familiars"""
  6. # Imports -------------------------------------------------------------
  7. import time
  8. import datetime
  9. import random
  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 Familiar:
  18. def __init__(self, acc):
  19. self.acc = acc
  20. self.userid = acc.getID()
  21. self.derg = None
  22. self.configspec = ConfigObj('config.spec', encoding='UTF8', list_values=False)
  23. self.config = ConfigObj('config.ini', configspec=self.configspec)
  24. val = Validator()
  25. test = self.config.validate(val, preserve_errors=True)
  26. self.mindelay = self.config['account']['bond']['mindelay']
  27. self.maxdelay = self.config['account']['bond']['maxdelay']
  28. self.check = False
  29. self.tried = 0
  30. def prebond(self):
  31. self.check = False
  32. self.tried = 0
  33. while not self.check:
  34. if (self.tried < 3):
  35. try:
  36. time.sleep(random.uniform(0.5, 2))
  37. html = self.acc.get('/main.php',
  38. param={
  39. 'p': 'lair',
  40. 'id': self.userid,
  41. },
  42. referer='/main.php?p=hoard'
  43. )
  44. self.check = True
  45. except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
  46. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Prebond_1_error_pageload')
  47. self.tried += 1
  48. pass
  49. else:
  50. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad network. Try again later.')
  51. sys.exit()
  52. dragons = re.findall('did=(\d*)', html.text)
  53. numpages = re.findall('id=' + self.userid + '&page=(\d+)', html.text)
  54. if numpages:
  55. if len(numpages) >= 2:
  56. for i in range(2, len(numpages) + 1):
  57. time.sleep(random.uniform(1, 3))
  58. self.check = False
  59. self.tried = 0
  60. while not self.check:
  61. if (self.tried < 3):
  62. try:
  63. htmld = self.acc.get('/main.php',
  64. param={
  65. 'p': 'lair',
  66. 'id': self.userid,
  67. 'page': str(i),
  68. },
  69. referer='/main.php?p=lair&id=' + self.userid + '&page=' + str(i - 1)
  70. )
  71. self.check = True
  72. except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
  73. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Prebond_2_error_dergcollect')
  74. self.tried += 1
  75. pass
  76. else:
  77. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad network. Try again later.')
  78. sys.exit()
  79. dragons += re.findall('did=(\d*)', htmld.text)
  80. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Begin Bonding!')
  81. self.derg = dragons[0]
  82. for x in dragons:
  83. time.sleep(random.uniform(self.mindelay, self.maxdelay))
  84. self.check = False
  85. self.tried = 0
  86. while not self.check:
  87. if (self.tried < 3):
  88. # print(x)
  89. try:
  90. html2 = self.acc.get('/main.php',
  91. param={
  92. 'p': 'lair',
  93. 'id': self.userid,
  94. 'tab': 'dragon',
  95. 'did': x,
  96. },
  97. referer='/main.php?p=lair&id=' + self.userid
  98. )
  99. famID = re.search("bondJamesbond\(\'(\d*)", html2.text)
  100. if famID:
  101. time.sleep(random.uniform(self.mindelay, self.maxdelay))
  102. html3 = self.acc.post('/includes/ol/fam_bonding.php',
  103. data={
  104. 'id': famID.group(1),
  105. },
  106. head={
  107. 'Accept': '*/*',
  108. 'Accept-Encoding': 'gzip,deflate',
  109. 'X-Requested-With': 'XMLHttpRequest',
  110. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  111. },
  112. referer='/main.php?p=lair&id=' +
  113. self.userid + '&tab=dragon&did=' + x
  114. )
  115. self.check = True
  116. # Have this ajaxlookup and print Names
  117. # Parse for rewards
  118. result = re.search("731d08;\">(.*?)</span>", html3.text)
  119. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' +
  120. result.group(1).replace('â\x80\x99', "'").replace('Ã\xB6', "o") + " bonded!")
  121. # if 'Death' in result.group(1):
  122. # print(result.group(1).encode())
  123. else:
  124. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Already Bonded ' + x + "'s familiar!")
  125. self.check = True
  126. except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
  127. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Prebond_3_error_post')
  128. self.tried += 1
  129. pass
  130. else:
  131. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad network. Try again later.')
  132. sys.exit()
  133. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + "Prebonding Complete!")
  134. def shuffle(self):
  135. self.check = False
  136. self.tried = 0
  137. while not self.check:
  138. if (self.tried < 3):
  139. try:
  140. html = self.acc.get('/main.php',
  141. param={
  142. 'p': 'lair',
  143. 'id': self.userid,
  144. 'tab': 'familiar',
  145. 'did': self.derg,
  146. },
  147. referer='/main.php?p=lair&id=' +
  148. self.userid + '&tab=dragon&did=' + self.derg
  149. )
  150. self.check = True
  151. except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
  152. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Shuffle_1_error_pageload')
  153. self.tried += 1
  154. pass
  155. else:
  156. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad network. Try again later.')
  157. sys.exit()
  158. # List the familiars that need bonding
  159. familiars = re.findall("\"attachFamiliar\(\'(\d+)'", html.text)
  160. for x in familiars:
  161. self.check = False
  162. self.tried = 0
  163. while not self.check:
  164. if (self.tried < 3):
  165. try:
  166. html2 = self.acc.get('/includes/familiar_active.php',
  167. param={
  168. 'id': self.derg,
  169. 'itm': x,
  170. },
  171. head={
  172. 'Accept': '*/*',
  173. 'X-Requested-With': 'XMLHttpRequest',
  174. },
  175. referer='/main.php?p=lair&id=' +
  176. self.userid + '&tab=familiar&did=' + self.derg
  177. )
  178. html3 = self.acc.get('/includes/familiar_inv.php',
  179. head={
  180. 'Accept': '*/*',
  181. 'X-Requested-With': 'XMLHttpRequest',
  182. },
  183. referer='/main.php?p=lair&id=' +
  184. self.userid + '&tab=familiar&did=' + self.derg
  185. )
  186. time.sleep(random.uniform(self.mindelay, self.maxdelay))
  187. self.check = True
  188. except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
  189. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Shuffle_2_error_famswitch')
  190. self.tried += 1
  191. pass
  192. else:
  193. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad network. Try again later.')
  194. sys.exit()
  195. self.check = False
  196. self.tried = 0
  197. while not self.check:
  198. if (self.tried < 3):
  199. # print(x)
  200. try:
  201. html4 = self.acc.get('/main.php',
  202. param={
  203. 'p': 'lair',
  204. 'id': self.userid,
  205. 'tab': 'dragon',
  206. 'did': self.derg,
  207. },
  208. referer='/main.php?p=lair&id=' +
  209. self.userid + '&tab=familiar&did=' + self.derg
  210. )
  211. famID = re.search("bondJamesbond\(\'(\d*)", html4.text)
  212. if famID:
  213. time.sleep(random.uniform(self.mindelay, self.maxdelay))
  214. html5 = self.acc.post('/includes/ol/fam_bonding.php',
  215. data={
  216. 'id': x,
  217. },
  218. head={
  219. 'Accept': '*/*',
  220. 'Accept-Encoding': 'gzip,deflate',
  221. 'X-Requested-With': 'XMLHttpRequest',
  222. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  223. },
  224. referer='/main.php?p=lair&id=' +
  225. self.userid + '&tab=dragon&did=' + self.derg
  226. )
  227. self.check = True
  228. # Have this ajaxlookup and print Names
  229. # Parse for rewards
  230. result = re.search("731d08;\">(.*?)</span>", html5.text)
  231. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' +
  232. result.group(1).replace('â\x80\x99', "'").replace('Ã\xB6', "o") + " bonded!")
  233. # if 'Death' in result.group(1):
  234. # print(result.group(1).encode())
  235. time.sleep(random.uniform(self.mindelay, self.maxdelay))
  236. else:
  237. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Already Bonded with ' + x)
  238. self.check = True
  239. except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
  240. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Shuffle_3_error_post')
  241. self.tried += 1
  242. pass
  243. else:
  244. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad network. Try again later.')
  245. sys.exit()
  246. self.check = False
  247. self.tried = 0
  248. while not self.check:
  249. if (self.tried < 3):
  250. try:
  251. html8 = self.acc.get('/main.php',
  252. param={
  253. 'p': 'lair',
  254. 'id': self.userid,
  255. 'tab': 'familiar',
  256. 'did': self.derg,
  257. },
  258. referer='/main.php?p=lair&id=' +
  259. self.userid + '&tab=dragon&did=' + self.derg
  260. )
  261. self.check = True
  262. time.sleep(random.uniform(self.mindelay, self.maxdelay))
  263. except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):
  264. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Shuffle_4_error_autopageload')
  265. self.tried += 1
  266. pass
  267. else:
  268. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + 'Bad network. Try again later.')
  269. sys.exit()
  270. print('[' + str(datetime.datetime.now().time())[:-3] + '] ' + "Done Bonding!")
  271. def bond(self):
  272. self.prebond()
  273. self.shuffle()
  274. os.system("pause")