didzislauva

gramblr_like_bot

Jul 5th, 2020
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.17 KB | None | 0 0
  1.  
  2. import requests
  3. import json
  4. import random
  5. import re
  6. import time
  7.  
  8.  
  9. class Gramblrscripter:
  10.     def __init__(self):
  11.         self.localhost_url="http://localhost.gramblr.com:4343"
  12.         self.earn_coins_url="http://localhost.gramblr.com:4343/api/gen_list_likes/didzislauva"
  13.         self.gramblr_url="http://localhost.gramblr.com:4343/api/users/current_identity"
  14.         self.add_likes_url="http://localhost.gramblr.com:4343/api/add_likes"
  15.         self.give_like_url="http://localhost.gramblr.com:4343/api/send_likes"
  16.  
  17.         self.h_language="en-US,en;q=0.8,lv;q=0.6"
  18.         self.h_useragent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"
  19.         self.h_cookie="gramblr.sessid=S_-puNAnE0jlhyAitQsYvzJvmLI4J5OMfcnqYFcVCUSiGYRJC5DNMbW3lKm2eEFw9j_Pw-VReMkShfEUR0g7T4Ng"; \
  20.                       "IsMember=1;"\
  21.                       "_ga=GA1.2.956286745.1516910888" \
  22.                       "validate_didzislauva=1; " \
  23.                       "NG_TRANSLATE_LANG_KEY=%22en%22"
  24.         self.h_connection="keep-alive' --compressed"
  25.         self.h_encoding="gzip, deflate, sdch"
  26.         self.h_accept="application/json, text/plain, */*"
  27.         self.users=[]
  28.         self.incomingString=""
  29.         self.payload=""
  30.  
  31.         self.results=""
  32.         self.liste=""
  33.         self.coins=0
  34.  
  35.  
  36.     def POST_list(self):
  37.         """
  38.         Does POST request with JSON edited list
  39.         """
  40.  
  41.         headers = {
  42.             "Accept":"application/json, text/plain, */*",
  43.             "Accept-Encoding":"gzip, deflate",
  44.             "Accept-Language":"en-US,en;q=0.8,lv;q=0.6",
  45.             "Connection":"keep-alive",
  46.             "Content-Length":439,
  47.             "Content-Type":"application/json;charset=UTF-8",
  48.             "Cookie":self.h_cookie,
  49.             "Host":"localhost.gramblr.com:4343",
  50.             "Origin":self.localhost_url,
  51.             "Referer":self.localhost_url+"/"
  52.         }
  53.  
  54.  
  55.         values=self.liste
  56.  
  57.  
  58.         results = requests.post(self.give_like_url,values,headers=headers)
  59.         print "POST LIST status code: \t\t\t| \t",results.status_code
  60.  
  61.     def gramblr_req(self):
  62.         """
  63.         Does GET request to get basic info of user
  64.         """
  65.         headers = {
  66.             "Accept-Encoding":self.h_encoding,
  67.             "Accept-Language":self.h_language,
  68.             "User-Agent":self.h_useragent,
  69.             "Accept":"application/json, text/plain, */*",
  70.             "Referer":self.localhost_url,
  71.             "Cookie":self.h_cookie,
  72.             "Connection":self.h_connection
  73.         }
  74.  
  75.         try:
  76.             results = requests.get(self.gramblr_url, headers=headers)
  77.             self.coins=json.loads(results._content)["coins"]
  78.             print "Amount of coins: \t\t\t\t|\t", json.loads(results._content)["coins"]
  79.         except:
  80.             print "unable to load"
  81.             self.gramblr_req()
  82.  
  83.  
  84.  
  85.     def pickIGfromFile(self,fname):
  86.         #fname='iglinks.txt'
  87.         with open(fname) as f:
  88.             content = f.readlines()
  89.             content = [x.strip() for x in content]
  90.  
  91.  
  92.         content=random.choice(content)
  93.         links=content
  94.         p=re.compile("(https?:\/\/(www\.)?)?instagram\.com(\/p\/[a-zA-Z0-9_-]*\/?)")
  95.         igLinkEnd= p.findall(content)[0][2][3:-1]
  96.  
  97.  
  98.  
  99.         headers = {
  100.             "Accept-Encoding":self.h_encoding,
  101.             "Accept-Language":self.h_language,
  102.             "User-Agent":self.h_useragent,
  103.             "Accept":"application/json, text/plain, */*",
  104.             "Referer":self.localhost_url,
  105.             "Cookie":self.h_cookie,
  106.             "Connection":self.h_connection
  107.         }
  108.  
  109.  
  110.         try:
  111.             results=requests.get("http://localhost.gramblr.com:4343/img_url/"+igLinkEnd,headers=headers)
  112.             self.igUser=json.loads(results._content)
  113.             self.igUser["links"]=links
  114.  
  115.  
  116.         except:
  117.             print "unable to select from instagram"
  118.             self.pickIGfromFile(fname)
  119.  
  120.  
  121.  
  122.     def POST_like(self,fname):
  123.         """
  124.         Does POST request 'like' to particular user,media_pk,user_pk
  125.         """
  126.         headers = {
  127.             "Origin":self.localhost_url,
  128.             "Accept-Encoding":"gzip, deflate",
  129.             "Accept-Language":self.h_language,
  130.             "User-Agent":self.h_useragent,
  131.             "Content-Type": "application/json;charset=UTF-8",
  132.             "Accept":self.h_accept,
  133.             "Referer":self.localhost_url,
  134.             "Cookie":self.h_cookie,
  135.             "Connection":self.h_connection
  136.         }
  137.  
  138.  
  139.  
  140.  
  141.  
  142.         self.pickIGfromFile(fname)
  143.  
  144.         try:
  145.             print  "lucky one - ", self.igUser["username"]
  146.             values='{"ig_user":"didzislauva",' \
  147.                    '"likes_qty":1,' \
  148.                    '"local_likes":false,' \
  149.                    '"media_pk":"'+self.igUser["media_pk"]+'",' \
  150.                    '"user_pk":'+str(self.igUser["user_pk"])+'}'
  151.             print self.igUser
  152.             results = requests.post(self.add_likes_url,values,headers=headers)
  153.             print "POST like status code: \t\t\t|\t", results.status_code
  154.         except:
  155.             print "once more - something wrong with link"
  156.             self.POST_like(fname)       #recursion
  157.  
  158.  
  159.  
  160.  
  161.     def GET_list(self):
  162.         """
  163.         Does GET request from 'gen_likes'
  164.         Prepares and returns JSON string from first to self.results
  165.         """
  166.         headers = {
  167.             "Accept-Encoding":"gzip, deflate, sdch",
  168.             "Accept-Language":self.h_language,
  169.             "User-Agent":self.h_useragent,
  170.             "Accept":"application/json, text/plain, */*",
  171.             "Referer":self.localhost_url,
  172.             "Cookie":self.h_cookie,
  173.             "Connection":self.h_connection
  174.         }
  175.  
  176.         results={}
  177.         results["list"]=False
  178.  
  179.         try:
  180.             counter=0
  181.             while not results["list"]:
  182.                 results = requests.get(self.earn_coins_url, headers=headers)
  183.                 self.results=results
  184.                 localtime = time.asctime( time.localtime(time.time()) )
  185.                 counter=counter+1
  186.                 print "GET LIST status code: \t\t\t|\t", results.status_code,  localtime, "\t|\t",counter #, results._content,
  187.  
  188.                 results=json.loads(results._content)
  189.                 time.sleep(1)
  190.  
  191.  
  192.             fullstrings=""
  193.  
  194.             iterstrings=iter(results["list"])
  195.  
  196.             print "Amount of loaded images: \t\t|\t", len(results["list"])
  197.             for each in iterstrings:
  198.                 fullstrings=fullstrings+'{"id":'+str(each["id"])+'},'
  199.  
  200.             self.liste='{"liked":[],"skipped":[],"ignored":['+fullstrings[:-1]+'],"ig_user":"didzislauva"}'
  201.             #print self.liste
  202.  
  203.  
  204.  
  205.  
  206.             self.results= self.results._content
  207.         except:
  208.             print "unable to load"
  209.             self.GET_list()
  210.  
  211.  
  212.  
  213.         try:
  214.  
  215.  
  216.  
  217.             outF=open("myOutFile.txt","r+")
  218.             userlist=set(str(line.strip()) for line in outF)
  219.             outF.close()
  220.  
  221.  
  222.             #prepare userlist
  223.             for counter, each in enumerate(results["list"]):
  224.                 print counter+1,":\t|\t","user id: \t", each["details"]["user_pk"],"\t| picture id: \t", each["details"]["ig_likes_ask_id"],"| username: \t",each["details"]["username"]
  225.                 userlist.add(str(each["details"]["username"]))
  226.             userlist=sorted(userlist)
  227.  
  228.  
  229.             outF=open("myOutFile.txt","r+")
  230.             #write users back in file
  231.             for each in userlist:
  232.                 outF.write(each)
  233.                 outF.write("\n")
  234.             outF.close()
  235.  
  236.             #print a
  237.         except:
  238.             print "unable to load list"
  239.             pass
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246. if __name__=="__main__":
  247.     print "main"
  248.  
  249.     import time
  250.     G = Gramblrscripter()
  251.  
  252.     G.gramblr_req()
  253.     coins_b=G.coins
  254.  
  255.  
  256.     ii=1000
  257.     for i in range(ii):
  258.         print ""
  259.         print "-------- ",i+1, " out of ", ii," --------------------"
  260.         print "--------  ielade listi"
  261.         G.GET_list() #ielaadee listi 1 #GET
  262.         #time.sleep(1)
  263.         print ""
  264.         print "--------  nolaiko bildi"
  265.         G.POST_like('iglinks.txt') #nolaiko bildi  #LIKEPOST
  266.         #time.sleep(1)
  267.         print ""
  268.         print "--------  aizsuta listi"
  269.         G.POST_list() #noposto listi #POST
  270.         print ""
  271.         print ""
  272.         print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  273.         #time.sleep(1)
  274.         G.gramblr_req()
  275.         coins_e=G.coins
  276.  
  277.         print "gained likes: \t\t\t\t\t|\t", (coins_e-coins_b)/10
  278.  
  279.         print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  280.         print ""
  281.         print ""
  282.         print time.asctime( time.localtime(time.time()) )
  283.  
  284.         coins_b=coins_e
  285.         #time.sleep(1)
Add Comment
Please, Sign In to add comment