Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.48 KB | None | 0 0
  1. import requests, json, time, threading
  2. from bs4 import BeautifulSoup
  3. from colorama import init, Fore
  4. import sys
  5.  
  6.  
  7. init()
  8.  
  9.  
  10. def get_page(s, url, headers=None):
  11. if headers is None:
  12. return s.get(url, timeout=2)
  13. return s.get(url, headers=headers, timeout=2)
  14.  
  15.  
  16. def post_page(s, url, payload, headers=None):
  17. return s.post(url, data=payload, headers=headers, allow_redirects=True, timeout=2)
  18.  
  19. def post_invite(s, url, payload, headers=None):
  20. return s.post(url, data=payload, headers=headers, allow_redirects=True, timeout=2)
  21.  
  22. def post_poach(s, url, payload, headers=None):
  23. return s.post(url, data=payload, headers=headers, timeout=2)
  24.  
  25.  
  26. def get_soup(page):
  27. return BeautifulSoup(page.content, 'html.parser')
  28.  
  29.  
  30. def get_history(page):
  31. return page.history
  32.  
  33.  
  34. def login_success(page):
  35. page_title = page.find('div', class_='page-title')
  36. if page_title is not None:
  37. if 'Вход в систему' in page_title.text:
  38. if page.find('div', attrs={'class': 'error-summary'}).get('style') is None:
  39. print('Логин или пароль не верный')
  40. print('Повторите вход')
  41. return False
  42. else:
  43. return True
  44.  
  45.  
  46. def load_cookies():
  47. with open('cookies.txt', 'r') as f:
  48. return requests.utils.cookiejar_from_dict(json.load(f))
  49.  
  50.  
  51. def save_cookies(s):
  52. with open('cookies.txt', 'w', encoding='utf-8') as f:
  53. json.dump(requests.utils.dict_from_cookiejar(s.cookies), f)
  54.  
  55.  
  56. def check_login_data():
  57. try:
  58. with open('login.txt', 'r') as f:
  59. line = f.readline(1)
  60. if not line:
  61. return
  62. else:
  63. return True
  64. except FileNotFoundError:
  65. return
  66.  
  67.  
  68. def read_login_data():
  69. with open('login.txt', 'r') as f:
  70. lines = [line.strip() for line in f.readlines()]
  71. return (lines[0], lines[1])
  72.  
  73.  
  74. def save_login_data():
  75. login = input('Введите логин: ').strip()
  76. password = input('Введите пароль: ').strip()
  77. with open('login.txt', 'w', encoding='utf-8') as f:
  78. f.write(login + '\n' + password)
  79.  
  80.  
  81. def net_waiter():
  82. while True:
  83. try:
  84. tmp = requests.get('https://jugl.net/', timeout=2)
  85. if tmp.status_code == 200:
  86. # print('Интернет впорядке.\nПродолжаю поиск...')
  87. break
  88. except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
  89. time.sleep(0.5)
  90.  
  91.  
  92. def exit0():
  93. global r
  94. while r:
  95. tmp = sys.stdin.read(1)
  96. if '\n' in tmp:
  97. r = False
  98.  
  99.  
  100. def main():
  101. s = requests.Session()
  102. base_url = 'https://jugl.net/'
  103.  
  104. if not check_login_data():
  105. save_login_data()
  106.  
  107. while True:
  108. try:
  109. login, password = read_login_data()
  110.  
  111. headers = {
  112. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
  113. 'Accept-Language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
  114. 'Origin': 'https://jugl.net',
  115. 'Content-Type': 'application/json;charset=UTF-8',
  116. # 'x-csrf-token': token,
  117. 'Referer': 'https://jugl.net/my',
  118. # 'accept': 'application/json, text/plain, */*',
  119. 'Accept-Encoding': 'gzip, deflate, br',
  120. # 'Content-Type': 'application/json;charset=UTF-8'
  121. }
  122.  
  123. token = get_soup(get_page(s, base_url + 'login', headers=headers)).find('input', {'name': '_csrf'}).get('value')
  124. payload = {'_csrf': token, 'LoginForm[username]': login, 'LoginForm[password]': password}
  125. logged = login_success(get_soup(post_page(s, base_url + 'login', payload, headers)))
  126. if logged is False:
  127. s.cookies.clear()
  128. save_login_data()
  129. else:
  130. break
  131. except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
  132. # print('Проблемы с интернетом.')
  133. net_waiter()
  134.  
  135. success = False
  136. while not success:
  137. try:
  138. my_name = get_page(s, base_url + 'api-user/status').text
  139. my_name = json.loads(my_name.)
  140. print(my_name)
  141. # my_last = json.loads(get_page(s, base_url + 'api-user/status').text[6:]).get('last_name')
  142. # My_Name = (my_name +' '+ my_last)
  143. success = True
  144. except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
  145. # print('Проблемы с интернетом.')
  146. net_waiter()
  147.  
  148. print(Fore.GREEN + 'Добро пожаловать', My_Name)
  149. print('Начинаю поиск новых людей...')
  150. print('Для отключения бота нажмите Enter')
  151. exiter = threading.Thread(target=exit0)
  152. exiter.start()
  153. User_Invite_New = None
  154. inviteng = True
  155. while r:
  156. # try:
  157. # requests.get('https://jugl.net/')
  158. # except requests.exceptions.ConnectionError:
  159. # print('Проблемы с интернетом.')
  160. # net_waiter()
  161. try:
  162. p1 = 'api-invite-my/list?country_ids=64,10,170,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196&pageNum=1'
  163. result = get_page(s, base_url + p1).text[6:]
  164. deco_invite = json.loads(result)
  165. items = deco_invite.get('log').get('items')
  166. First_name = items[0]['first_name']
  167. Last_name = items[0]['last_name']
  168. User_Invite = (First_name + ' ' + Last_name)
  169. Id = items[0]['id']
  170. if 'winner' not in items[0] and inviteng:
  171. print('Пытаюсь пригласить: ' + User_Invite)
  172. payload = {'_csrf': token, 'id': Id}
  173. invite = get_soup(post_invite(s, base_url + 'api-invitation/become-member-invite', payload, headers)).text[6:]
  174. print(json.loads(invite))
  175. inviteng = False
  176. continue
  177. elif 'winner' not in items[0]:
  178. continue
  179. User_Invite_Old, User_Invite_New = (User_Invite, User_Invite_New)[User_Invite_New!=None], User_Invite
  180. User_Winner = items[0]['winner']['userName']
  181.  
  182. if My_Name in User_Winner and User_Invite_New!=User_Invite_Old:
  183. print('Ура пригласил! ' + User_Invite_New)
  184. elif User_Invite_New!=User_Invite_Old:
  185. print('К сожалению не пригласил, будем переманивать: ' + User_Invite_New)
  186. inviteng = True
  187. time.sleep(2)
  188. poach_get = get_page(s, base_url + 'api-user-profile/index?id=369060', headers)
  189. time.sleep(1)
  190. print(poach_get.text)
  191. print(poach_get.cookies)
  192.  
  193. payload = {'_csrf': token, 'userTeamRequest': {'user': {'name': 'Sylvia jones'}, 'second_user_id': 369060, 'text': "Приветствую Вас, приглашаю к себе в команду, буду во всем помогать для достижения успеха и больших заработков. Предоставлю Вам видео уроки", "saving":'true'}}
  194. poach = post_page(s, base_url + 'api-user-team-request/save-parent-to-referral', payload, headers)
  195. print(poach.text)
  196. print(poach.status_code)
  197. # print(s.cookies)
  198. break
  199. except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
  200. # print('Проблемы с интернетом.')
  201. net_waiter()
  202.  
  203. if __name__ == '__main__':
  204. global r
  205. r = True
  206. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement