Skip to content

Instantly share code, notes, and snippets.

@pwldp pwldp/gen_apple_ids.py

Last active Aug 29, 2015
Embed
What would you like to do?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generates CSV file for Apple-ID-AppleScript
# https://github.com/aaronfreimark/Apple-ID-AppleScript
#
# Dariusz Pawlak <pawlakdp@gmail.com>
# 2014.09.15
#
# According to http://stackoverflow.com/questions/10748453/replace-comma-with-newline-in-sed
# replace end of lines in generated file by ^j, for example:
#
# sed 's/\^/\^J/g' appleids_from_script.csv > appleids_from_script_newlines.csv
#
# where ^J is ctrl_+v+j
#
#
#
import random
import re
import string
#
#==============================================================================
#
security_questions = {
1: {
0: "What is the first name of your best friend in high school?",
1: "What was the name of your first pet?",
2: "What was the first thing you learned to cook?",
3: "What was the first film you saw in the theater?",
4: "Where did you go the first time you flew on a plane?",
5: "What is the last name of your favorite elementary school teacher?"
},
2:{
0: "What is your dream job?",
1: "What is your favorite children's book?",
2: "What was the model of your first car?",
3: "What was your childhood nickname?",
4: "Who was your favorite film star or character in school?",
5: "Who was your favorite singer or band in high school?"
},
3:{
0: "In what city did your parents meet?",
1: "What was the first name of your first boss?",
2: "What is the name of the street where you grew up?",
3: "What is the name of the first beach you visited?",
4: "What was the first album that you purchased?",
5: "What is the name of your favorite sports team?"
}
}
#
#==============================================================================
#
security_questions_answers = {
1: {
0: ["Adam", "Darek", "Amanda", "Ronnie", "Anna"],
1: ["Chleo", "Mar", "Hector", "Scout", "Bonzo"],
2: ["black pudding", "dumplings", "fish and chips", "roast beef", "pizza"],
3: ["The Godfather", "The Shawshank Redemption", "Star Wars", "Pulp Fiction", "King Kong"],
4: ["Shanghai", "Delhi", "Seoul", "Jakarta", "Tokyo"],
5: ["Morgan", "Leroy", "Calvin", "Grimm", "Edmonds"]
},
2: {
0: ["astronaut", "engineer", "teacher", "boss", "explorer"],
1: ["The Little Prince", "Pippi Longstocking", "Winnie The Pooh", "The Secret Garden", "The Hobbit"],
2: ["Yugo", "Multipla", "Pinto", "Aztek", "Aerostar"],
3: ["Bebo", "Cookie", "Dear", "Mookie", "Tyke"],
4: ["Robert Downey Jr.", "Leonardo DiCaprio", "Meryl Streep", "Jennifer Lawrence", "Conchita Wurst"],
5: ["U2", "Aerosmith", "Abba", "Queen", "Nirvana"]
},
3: {
0: ["London", "Bangkok", "Paris", "Dubai", "Venice"],
1: ["Zeus", "Capone", "Escobar", "Luciano", "Gotti"],
2: ["Main", "Elm", "Cedar", "Oak", "Hill"],
3: ["Baia do Sancho", "Grace Bay", "Flamenco Beach", "Rabbit Beach", "Whitehaven"],
4: ["Thriller", "Rumours", "Nevermind", "Supernatural", "Daydream"],
5: ["Real", "Manchester", "Yankees", "Redskins", "Arsenal"]
}
}
#
csvHeader="""Email,Password,Secret Question 1,Secret Answer 1,Secret Question 2,Secret Answer 2,Secret Question 3,Secret Answer 3,Month Of Birth,Day Of Birth,Year Of Birth,First Name,Last Name,Address Street,Address City,Address State,Address Zip,Phone Area Code,Phone Number,Rescue Email (Optional),Account Status"""
#
#==============================================================================
#
#
#==============================================================================
#
config = {
"csv_name": "appleids_from_script.csv",
"start_account_number": 100,
"accounts_quantity": 401,
"email_format": "ipad%04d@domain.tld",
"month_of_birth": "January",
"day_of_birth": "01",
"year_of_birth": "1970",
"first_name": "Ipad",
"last_name": "",
"street": "Main",
"city": "",
"state": "Moon",
"zip": "01234",
"phone_area_code": "48",
"phone_number": "123456789", # optional
"rescue_email": "rescue@domain.tld",
"account_status": "active"
}
#
#------------------------------------------------------------------------------
#
def genApplePassword():
"""
According to http://support.apple.com/kb/ht4232 :
Apple policy requires you use strong passwords with your Apple ID. Your password must have a minimum of 8 characters, not contain more than 3 consecutive identical characters, and include a number, an uppercase letter, and a lowercase letter.
Based on: # http://en.wikipedia.org/wiki/Random_password_generator#Python
"""
validPassword = False
#validPassword = True
length = 8
while True:
myrg = random.SystemRandom()
# If you want non-English characters, remove the [0:52]
alphabet = string.letters[0:52] + string.digits
pw = str().join(myrg.choice(alphabet) for _ in range(length))
#
if re.search("[a-z]", pw):
validPassword = True
#
if re.search("[A-Z]", pw):
validPassword = True
#
if re.search("[0-9]", pw):
validPassword = True
#
if validPassword:
break
#
#
return pw
#
#------------------------------------------------------------------------------
#
def genSecretQuestion( question_number ):
questionNum = random.randint(0, len(security_questions[ question_number ])-1 )
question = security_questions[question_number][ questionNum ]
answerNum = random.randint(0, len(security_questions_answers[question_number][ questionNum ])-1 )
answer = security_questions_answers[question_number][ questionNum ][answerNum]
return [question, answer ]
#
#==============================================================================
#
if __name__ == "__main__":
print "Start generating do for Apple-ID-AppleScript..."
#
fcsv = open(config['csv_name'], "w")
fcsv.write("%s\n" % csvHeader)
#
for cnt in range( config['accounts_quantity'] ):
accNumber = config['start_account_number'] + cnt
print "#%s account" % accNumber
row = "%s," % (config["email_format"] % accNumber)
#
row+= "%s," % genApplePassword()
#
qa = genSecretQuestion(1)
row+= "%s,%s," % (qa[0],qa[1])
qa = genSecretQuestion(2)
row+= "%s,%s," % (qa[0],qa[1])
qa = genSecretQuestion(3)
row+= "%s,%s," % (qa[0],qa[1])
#
row+= "%s," % config["month_of_birth"]
row+= "%s," % config["day_of_birth"]
row+= "%s," % config["year_of_birth"]
#
row+= "%s," % config["first_name"]
#
if len(config['last_name']) == 0:
row+= "Surname_%s," % cnt
else:
row+= "%s," % config['last_name']
#
row+= "%s," % config["street"]
row+= "%s," % config["city"]
row+= "%s," % config["state"]
row+= "%s," % config["zip"]
#
row+= "%s," % config["phone_area_code"]
row+= "%s," % config["phone_number"]
#
row+= "%s," % config["rescue_email"]
#
row+= "%s" % config["account_status"]
#
fcsv.write( "%s^" % row )
#
fcsv.close()
#
# remove last blank line from file
with open(config['csv_name'], 'rb+') as f:
f.seek(0,2)
size=f.tell()
f.truncate(size-1)
#
#
# EOF
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.