Repeat Sequence - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Repeat Sequence (/thread-6678.html) |
Repeat Sequence - TulsaTough - Dec-03-2017 Hello... I am new to Python. I am trying to get the code below to repeat. This is a voting hack. It votes 23 times and then quits. I would like it to go through the sequence, be idle for 60 seconds and then repeat as many times as desired. I appreciate you taking the time to help me! base_url = "https://polldaddy.com/poll/" redirect = "" useragents = current_useragent = "" proxies = current_proxy = {"http":""} current_proxy_num = -1 def get_all_useragents(): f = open("useragent.txt", "r") for line in f: useragents.append(line.rstrip('\n').rstrip('\r')) f.close() def choose_useragent(): k = random.randint(0, len(useragents)-1) current_useragent = useragents[k] #print current_useragent def get_all_proxies(): f = open("proxy.txt", "r") for line in f: proxies.append(line.rstrip('\n').rstrip('\r')) f.close() def choose_proxy(): k = random.randint(0, len(proxies)-1) current_num = k current_proxy["http"] = proxies[k] def vote_once(form, value): c = requests.Session() #Chooses useragent randomly choose_useragent() redirect = {"Referer": base_url + str(form) + "/", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "User-Agent": current_useragent, "Upgrade-Insecure-Requests":"1", "Accept-Encoding": "gzip, deflate, sdch", "Accept-Language": "en-US,en;q=0.8"} # Chooses proxy randomly choose_proxy() try: init = c.get(base_url + str(form) + "/", headers=redirect, verify=False, proxies=current_proxy) except: print ("error with proxy") #proxies.remove(current_proxy_num) return None # Search for the data-vote JSON object data = re.search("data-vote=\"(.*?)\"",init.text).group(1).replace('"','"') data = json.loads(data) # Search for the hidden form value pz = re.search("type='hidden' name='pz' value='(.*?)'",init.text).group(1) # Build the GET url to vote request = "https://polldaddy.com/vote.php?va=" + str(data['at']) + "&pt=0&r=0&p=" + str(form) + "&a=" + str(value) + "%2C&o=&t=" + str(data['t']) + "&token=" + str(data['n']) + "&pz=" + str(pz) try: send = c.get(request, headers=redirect, verify=False, proxies=current_proxy) except: print ("error with proxy") #proxies.remove(current_proxy_num) return None return ("revoted" in send.url) def vote(form, value, times, wait_min = None, wait_max = None): global redirect # For each voting attempt i = 1 while i < times+1: b = vote_once(form, value) # If successful, print that out, else try waiting for 60 seconds (rate limiting) if not b: # Randomize timing if set if wait_min and wait_max: seconds = random.randint(wait_min, wait_max) else: seconds = .5 print ("Voted (time number " + str(i) + ")!") time.sleep(seconds) else: print ("Locked. Sleeping for 60 seconds.") i-=1 time.sleep(60) i += 1 def repeat_to_length(string_to_expand, length): return (string_to_expand *7 (int(length/len(string_to_expand))+1))[:length] # Initialize these to the specific form and how often you want to vote poll_id = xxxxxxxxx answer_id = xxxxxxx number_of_votes = 23 wait_min = None wait_max = None get_all_proxies() get_all_useragents() vote(poll_id, answer_id, number_of_votes, wait_min, wait_max) RE: Repeat Sequence - nilamo - Dec-03-2017 You already vote once. Use a for loop and do it multiple times? |