Advertisement
Guest User

Untitled

a guest
Jan 7th, 2018
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 KB | None | 0 0
  1. import requests
  2. from bs4  import BeautifulSoup
  3. import time
  4. import sys
  5. import datetime
  6. import os
  7. from random import randint
  8. BASE_URL = "http://fubar.com"
  9. USERNAME = "tmp@tmp.com"
  10. PASSWORD = "123123"
  11. VOTE = 0
  12. GROUP = 1
  13. UID = 2
  14. GUID = 3
  15. LOC = 4
  16.  
  17. rates = 0
  18.  
  19. s = requests.Session()
  20. s.get(BASE_URL + "/login.php?dest=home.php")
  21.  
  22. def print_ts(str):
  23.     ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
  24.     print(ts + " - " + str)
  25.    
  26.    
  27. def parse_js_button(js):
  28.     js_list = js[28:-2].split(',')
  29.     return js_list
  30.    
  31. def parse_js_vote(js_list):
  32.     ret = {"vote" : int(js_list[VOTE]), "uid" : int(js_list[UID]), "guid" : int(js_list[GUID][1:-1]), "group" : int(js_list[GROUP]), "spoof" : 1, "loc" : js_list[LOC]}
  33.     print_ts ("Preparing statement : " + str(ret))
  34.     return ret
  35.    
  36. def parse_js_rate(js_list, rating):
  37.     ret = {"owner" : int(js_list[UID]), "rating" : rating}
  38.     print_ts ("Preparing statement : " + str(ret))
  39.     return ret
  40.    
  41. params = {"dest" : "/home.php", "_user" : USERNAME, "_pw" : PASSWORD, "remember_me" : "on"}
  42. ret = s.post(BASE_URL + "/login.php", data=params)
  43. print_ts("Logged in with status code: " + str(ret.status_code))
  44.  
  45. idx = 0
  46.  
  47. while True:
  48.     try:
  49.         print_ts("idx: " + str(idx))
  50.         res = s.get(BASE_URL + "/whosonline.php?idx=" + str(idx))
  51.         soup = BeautifulSoup(res.content, "html.parser")
  52.         users = soup.findAll('div', attrs={"class" : "user_tn_tiny_5"})
  53.         links = []
  54.         for user in users:
  55.             link = user.find('a')
  56.             links.append(link['href'])
  57.         print_ts("Links: " + str(links))
  58.         if (len(links) == 0):
  59.             print("No new links, check your account. Terminating...")
  60.             os._exit(-1)
  61.         idx += len(links)
  62.         print_ts("Got " + str(len(links)) + " links")
  63.         for link in links:
  64.             print_ts("User: " + link)
  65.             profile = s.get(BASE_URL + link)
  66.             profile_bs = BeautifulSoup(profile.content, "html.parser")
  67.             like_button = profile_bs.find('a', attrs={'class' : 'profile_like'})
  68.             if (like_button == None):
  69.                 print_ts("Already liked")
  70.                 print_ts("Sleeping for 3 secs")
  71.                 time.sleep(3)
  72.             else:
  73.                 js_list = parse_js_button(like_button['onclick'])
  74.                 params = parse_js_vote(js_list)
  75.                 ret = s.post(BASE_URL + "/a_vote.php", data=params)
  76.                 print_ts("Sent a POST like request, returned: " + str(ret.status_code))
  77.                 params = parse_js_rate(js_list, randint(7, 11))
  78.                 ret = s.post(BASE_URL + "/a_rate_user.php", data=params)
  79.                 print_ts("Sent a POST rate request, returned: " + str(ret.status_code))
  80.                 print_ts("Sleeping for 5 secs")
  81.                 time.sleep(5)
  82.         print_ts("Completed a batch, sleeping for 30 secs")
  83.         time.sleep(30)
  84.     except KeyboardInterrupt:
  85.         sys.exit()
  86.     except requests.exceptions.RequestException as e:  # This is the correct syntax
  87.         print(e)
  88.     except:
  89.         print_ts("Caught an exception!")
  90.         continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement