Created
January 15, 2022 10:31
-
-
Save lukacat10/82dd9605b003a47e3309f274ae71b901 to your computer and use it in GitHub Desktop.
A set of scripts for generating good or bad israeli phone numbers and ids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import csv | |
def generate_random_israeli_phone_number(): | |
prefix = random.choice(["050", "052", "053", "054", "055", "058"]) | |
main = random.randint(0, 9999999) | |
mainstr = str(main) | |
mainstr = "0" * (7 - len(mainstr)) + mainstr | |
complete = prefix + mainstr | |
return complete | |
def generate_unreliable_random_israeli_phone_number(): | |
bomb_with_zeros = random.randint(1, 100) | |
if bomb_with_zeros >= 1 and bomb_with_zeros <= 5: # The odds of having a "zeros bomb" | |
return "0000000000" | |
prefix = random.choice(["02", "03", "04", "050", "052", "053", "054", "055", "058"]) | |
main = random.randint(0, 9999999) | |
mainstr = str(main) | |
mainstr = "0" * (random.randint(len(mainstr), 7) - len(mainstr)) + mainstr | |
complete = prefix + mainstr | |
return complete | |
def generate_bad_random_israeli_phone_number(): | |
randnumber = generate_unreliable_random_israeli_phone_number() | |
while validate_israeli_phone_number(randnumber): | |
randnumber = generate_unreliable_random_israeli_phone_number() | |
return randnumber | |
def validate_israeli_phone_number(checknumber): | |
checknumberstr = str(checknumber) | |
if checknumberstr[0:3] not in ["050", "052", "053", "054", "055", "058"]: | |
return False | |
if len(checknumberstr) < 10: | |
return False | |
return True | |
CONST_ONE_TWO = [1, 2] * 4 + [1] | |
def validate_id(checkid): | |
checkidstr = str(checkid) | |
checkidstr = "0" * (9 - len(checkidstr)) + checkidstr | |
multiplied = [0] * 9 | |
for i in range(9): | |
multiplied[i] = int(checkidstr[i]) * CONST_ONE_TWO[i] | |
if multiplied[i] > 9: | |
asstr = str(multiplied[i]) | |
sum_asstr = 0 | |
for num in asstr: | |
sum_asstr += int(num) | |
multiplied[i] = sum_asstr | |
summed_multiplied = sum(multiplied) | |
if summed_multiplied % 10 == 0: | |
return True | |
return False | |
def generate_id(): | |
randid = random.randint(0, 999999999) | |
while not validate_id(randid): | |
randid = random.randint(0, 999999999) | |
return randid | |
def generate_bad_id(): | |
randid = random.randint(0, 999999999) | |
while validate_id(randid): | |
randid = random.randint(0, 999999999) | |
return randid | |
def generate_info(count): | |
with open('employee_file.csv', mode='w') as employee_file: | |
employee_writer = csv.writer(employee_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) | |
for i in range(count): | |
should_be_bad_number = random.randint(1, 100) | |
should_be_bad_id = random.randint(1, 100) | |
if should_be_bad_id >= 1 and should_be_bad_id <= 10: | |
id = generate_bad_id() | |
goodid = False | |
else: | |
id = generate_id() | |
goodid = True | |
if should_be_bad_number >= 1 and should_be_bad_number <= 10: | |
number = generate_bad_random_israeli_phone_number() | |
goodnumber = False | |
else: | |
number = generate_random_israeli_phone_number() | |
goodnumber = True | |
employee_writer.writerow([id, number, goodid, goodnumber]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment