-
Notifications
You must be signed in to change notification settings - Fork 1
/
plates.py
executable file
·95 lines (80 loc) · 2.74 KB
/
plates.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
import enchant
import glob
import os
import string
import sys
import uuid
from joblib import Parallel, delayed
import multiprocessing
num_cores = multiprocessing.cpu_count()
chars = string.uppercase[:26]
chars_rnd = chars.replace("I", "")
chars_rnd = chars_rnd.replace("Q", "")
chars_pre = chars_rnd.replace("Z", "")
nums = "OIZSB"
no_s = "01258"
nums_used = [ "SI", "OZ", "SZ", "OA", "SA", "0S", "SS", "OT", "ST", "OB", "SB", "OG", "SG", "IO", "GO", "II", "IZ", "GZ", "IA", "GA", "IS", "GS", "IG", "GG", "IT", "GT" ]
nums_conv = [ "51", "02", "52", "04", "54", "05", "55", "07", "57", "08", "58", "06", "56", "10", "60", "11", "12", "62", "14", "64", "15", "65", "16", "66", "17", "67" ]
def convert_plate(plate):
for idx, used in enumerate(nums_used):
real_plate = plate[:2] + plate[2:4].replace(used, nums_conv[idx]) + plate[4:]
if real_plate != plate:
break
return real_plate
print "Welcome to plate finder (running with " + str(num_cores) + " cores)"
dict = enchant.Dict("en_GB")
count = 0
found = 0
output = "plates"
ext = ".txt"
def process_plate(c1):
out = open(output + "-" + str(uuid.uuid4()) + ext, "w")
for c2 in chars_pre:
for c34 in nums_used:
for c5 in chars_rnd:
for c6 in chars_rnd:
for c7 in chars_rnd:
plate = c1 + c2 + c34 + c5 + c6 + c7
if dict.check(plate):
new_plate = convert_plate(plate)
print plate + " becomes " + new_plate
new_plate+="\n"
out.write(new_plate)
out.close()
def process_short(c1):
out = open(output + "-" + str(uuid.uuid4()) + ext, "w")
for c2 in chars_pre:
for c34 in nums_used:
for c5 in chars_rnd:
for c6 in chars_rnd:
for c7 in chars_rnd:
plate1 = c1 + c2 + c34
plate2 = c5 + c6 + c7
if dict.check(plate1) and dict.check(plate2):
new_plate = convert_plate(plate1)
print plate1 + " " + plate2 + " becomes " + new_plate + " " + plate2
out.write(new_plate + plate2 + "\n")
out.close()
content = Parallel(n_jobs=num_cores)(delayed(process_plate)(i) for i in chars_pre)
content = Parallel(n_jobs=num_cores)(delayed(process_short)(i) for i in chars_pre)
filenames = glob.glob(output + "-*" + ext)
print filenames
with open(output + ext, 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
for line in infile:
outfile.write(line)
for file in filenames:
os.remove(file)
print "Sorting alphabetically"
original = open(output + ext, "r")
lineList = original.readlines()
original.close()
out = open(output + ext, "w")
for line in sorted(lineList):
print line
out.write(line.rstrip())
out.write("\n")
out.close()
print "All Done"