Reputation: 327
The script logs into a website (signin()) and then registers for an event (registerforevent()).
How do I make this script run multiple times and each time using a different email and password from a list to sign in and register?
Code:
import requests
import time
import random
def signin():
sess=requests.session()
url = "https://www.DOMAINE.com"
payload = {"username":email,"password":password}
r = requests.post(url,json=payload)
print(r.status_code)
def registerforevent():
sess=requests.session()
url2 = "https://www.DOMAINE.com"
payload = {"username":email,"password":password}
r = requests.post(url2,json=payload)
print(r.status_code)
signin()
registerforevent()
Data file:
[email protected]:Password123
[email protected]:Password123
[email protected]:Password123
[email protected]:Password123
[email protected]:Password123
Upvotes: 4
Views: 1331
Reputation: 128
You need to give your signin()
and registerforevent()
functions email
and password
arguments; for example:
def signin(email, password):
....
def registerforevent(email, password):
....
Then you can simply run your functions in a loop that iterates over your different emails and password pairs and input them into the functions. There are many ways to do such a loop and it will depend on how you are storing and accessing each unique email/password pair.
One example is if you had your credentials stored in a python dictionary where the key could be the email address and value the password, e.g:
credentials = {"[email protected]": 'password1234', "[email protected]": '1234password'}
for email, password in credentials.items():
signin(email, password)
registerforevent(email, password)
Note: credentials.items()
for python 3.x and credentials.iteritems()
for python 2.x
Upvotes: 1
Reputation: 78680
All you really need are some minor adjustments to your functions and a for
loop. I won't explicitly give you the finished code, but here's the procedure:
Write signin
and registerforevent
such that they accept the address and the password as arguments. Loop over the lines in your file, split each line by :
and call your two functions in each iteration. Pretty straight forward.
Alternatively, call your script from the command line with different sys.args
.
Upvotes: 0