-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_acn_abn.py
65 lines (56 loc) · 2.32 KB
/
generate_acn_abn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
'''
For information on the logic implementation, refer to the following Australian government links
ABN - https://abr.business.gov.au/Help/AbnFormat (Also you can validate the abn generated by the script on this link too)
ACN - https://asic.gov.au/for-business/registering-a-company/steps-to-register-a-company/australian-company-numbers/australian-company-number-digit-check/
'''
from random import randint
import csv
ABN_TO_GENERATE = 10 # number of abn to generate
ACN_TO_GENERATE = 10 # number of acn to generate
def generate_abn(count):
abn_list = []
digit_identifier = 9
abn_weight_factor = [3,5,7,9,11,13,15,17,19]
abn_list.append('abn_numbers')
try:
for j in range(count):
sABN = ''.join(["{}".format(randint(0, digit_identifier)) for num in range(0, digit_identifier)])
result_sum = int(0)
for i in range(9):
result_sum = result_sum +((int(sABN[i]))*(int(abn_weight_factor[i])))
result_sum = result_sum % 89
result_sum = 89 - result_sum
result_sum = result_sum + 10
abn_list.append(str(result_sum)+sABN)
with open('./abn.csv', 'w') as abn_file:
file_writer = csv.writer(abn_file,quoting=csv.QUOTE_ALL,delimiter='\n')
file_writer.writerow(abn_list)
except Exception as e:
raise e
def generate_acn(count):
acn_list = []
digit_identifier = 9
acn_weight_factor = [8,7,6,5,4,3,2,1]
acn_list.append('acn_numbers')
try:
for j in range(count):
sACN = ''.join(["{}".format(randint(0, digit_identifier)) for num in range(0, 8)])
result_sum = int(0)
for i in range(8):
result_sum = result_sum +((int(sACN[i]))*(int(acn_weight_factor[i])))
result_sum = result_sum % 10
result_sum = 10 - result_sum
if (result_sum == 10):
result_sum = 0
acn_list.append(sACN+str(result_sum))
with open('./acn.csv', 'w') as acn_file:
file_writer = csv.writer(acn_file,quoting=csv.QUOTE_ALL,delimiter='\n')
file_writer.writerow(acn_list)
except Exception as e:
raise e
def main():
generate_abn(ABN_TO_GENERATE)
#generate_acn(ACN_TO_GENERATE)
if __name__ == "__main__":
main()