mardi 18 août 2015

Simple account registration using Python

So currently I'm working on python app which will automatically register new accounts. The webstite is: "http://ift.tt/1LhfMgN"

I have some code, which: Takes 4 inputs: region (it can change the url from eune[...] to euw/na etc.), password for all accounts (if nothing entered it will generate a random password), number of account to create and a separator between username and password (app will save it to .txt file like username:password or username|password)

So, variables: url, username, password, email (username@gmail.com), dob (Date of Birth - dob[0] = dd, dob[1] = mm, dob[2] = yyyy). I don't worry about captcha atm

Code:

from random import randint
import string
import requests
import urllib2
import random
from BeautifulSoup import BeautifulSoup

#Regions : EUNE, EUW, NA, LAN, LAS, BR

#Username : 4-24 length, only letters and numbers
#Password : 6-16 length, at least 1 number and one letter, no ", / ."
#Password2 : = Password
#E-mail : Username@gmail.com
#Date of Birth : randomint(1-30), randomint(1-12), randomint(1980-1996)
#Terms of use : 1 checkbox (has to be checked)
#Captcha : img, then a Label to input a captcha text
#Play for free button : just imitate a click on that

#Files to work on : names.txt, created_accounts.txt
#Possible separators : ":" and "|"

#Variables used : username, password, email

created = []
def saveAcc(username, password):
    username = username
    password = password
    fid = open('created_accounts.txt', 'w')
    fid.write("\n%s%s%s\t" +time) % (username, sep, password)
    fid.close()
    created.append(username)
def createAcc(region, password, number, sep):
    #So for now we have those variables: region(Region), password(if given), number(Number of accs to create), sep(A separator between username and password)
    region = region
    password = password
    number =  number
    sep = sep
    #Setting a url to register using the region given from input
    url = "https://signup." +region+"http://.leagueoflegends.com/pl/signup/index?realm_key=" +region
    #creating a random username
    fid = open('names.txt', 'r')
    names = fid.readlines()
    names2 = random.choice(names)
    username = names2[:len(names2)-1] + str(randint(100,1000))
    #Creating a e-mail equal to random username + @gmail.com
    email = username+"@gmail.com"
    #Checking if password is valid
    if len(password) <= 6:
        #checking if password should be random
        if password == "":
            #creating a random password
            def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
                return ''.join(random.choice(chars) for _ in range(size))
            password = id_generator()
        elif password != "":
            print "Invalid password!"
    #Creating a list which : [0] is a day, [1] is a month and [2] is a year
    dob = []
    dob.append(randint(10,30))
    dob.append(randint(1,12))
    dob.append(randint(1980, 1996))
    #Creating new variables : dd for Day, mm for Month and yyyy for Year
    dd = dob[0]
    mm = dob[1]
    yyyy = dob[2]
    #Username, e-mail and password are strings! Dates of birth are integers!!!
    #debug()
    print "\nURL: %s" % url
    print "Region: %s" % region
    print "Username: %s" % username
    print "Password: %s" % password
    print "E-mail: %s" % email
    print "Date of Birth: %s %s %s" % (str(dob[0]), str(dob[1]), str(dob[2]))
    print "Number of accounts: %s" % number
    print "Separator: %s" % sep
    #Here comes the hardest part, the WEB part:



    #Saving a created account to created_accounts.txt
    #saveAcc(username, password) --- commented just to not use it for now
def main():
    print "Regions : EUNE, EUW, NA, LAN, LAS, BR"
    print "Password may only contain letters and numbers!!!!!!!"
    print 'Possible separators : ":" and "|"\n'
    region = raw_input("Region: ").lower()
    password = raw_input("Password for your accounts (if u want random pass,    then skip it with ENTER)")
    number = int(raw_input("Number of accounts to create: "))
    sep =  raw_input("Separator?: ")    
    createAcc(region, password, number, sep)
    #To delete, when we finish a code (when no debug is needed):
    #debug()
    #for i in range(number):
        #createAcc()
    #print "We've created " +len(created)+ "accounts successfully"      
main()

Now in createAcc() I want to fill the inputs on this site, which are: Username, Password, Re-enter password, E-mail, Date of Birth, Check 1st box (Terms of Use) and soon(tm) captcha. How can I do this? I will be using variables: username, password, email, dob




Aucun commentaire:

Enregistrer un commentaire