Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repeat Sequence
#1
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)
Reply
#2
You already vote once.  Use a for loop and do it multiple times?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,373 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Repeat request by else stsxbel 2 1,195 Jul-30-2022, 03:34 PM
Last Post: stsxbel
  get out of while loop and stop repeat Frankduc 11 3,061 Apr-26-2022, 10:09 PM
Last Post: deanhystad
  Avoid multiple repeat in indent Frankduc 8 2,920 Jan-18-2022, 05:46 PM
Last Post: Frankduc
  How to discard list repeat values akanowhere 7 3,746 Dec-28-2020, 09:14 PM
Last Post: akanowhere
  I want to check if the input is str or is int & if it's str repeat the loop HLD202 4 2,825 Nov-23-2020, 11:01 PM
Last Post: perfringo
  is there a way: repeat key word args Skaperen 2 2,259 Feb-03-2020, 06:03 PM
Last Post: Skaperen
  Python Script to repeat Photoshop action in folders and subfolders silfer 2 4,590 Jul-25-2019, 03:12 PM
Last Post: silfer
  Trying to Repeat a Function? DanielHetherington 1 2,364 Mar-27-2019, 09:48 PM
Last Post: SheeppOSU
  While loop repeat Runner83 5 4,305 Nov-11-2018, 10:50 AM
Last Post: MasterJediKnight7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020