-
Notifications
You must be signed in to change notification settings - Fork 0
/
plane.py
93 lines (75 loc) · 3.13 KB
/
plane.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
import sys
import os
import yaml
import uuid
import pathlib
class Plane:
def __init__(self, filepath):
self.abs_path = str(pathlib.Path(__file__).parent.absolute()) + '/'
self.config_file = self.abs_path + 'codes.yaml'
self.filepath = filepath
self.uid = str(uuid.uuid4())
def get_yaml(self):
with open(self.config_file) as file:
full_codes = yaml.load(file)
return full_codes
return None
def decode_this(self):
keypath = self.abs_path + 'static/keys/' + self.uid + '.key'
cmd = 'python2 ' + self.abs_path + 'img_to_data/pdf417.py ' + self.filepath + ' > ' + keypath
res = os.system(cmd)
print("cmd = " + cmd + '\nRes = '+ str(res))
print("Keypath = " + keypath)
with open(keypath) as fd:
text = fd.read()
text = text.replace('\t', '')
text = text.replace('\n', '')
print("-----> This is the Text : " + text + " <--- End Text")
if text[0] != 'M':
text = 'M' + text # Sometimes -Always-, the first M is not read so I add it manually
table = text.split(' ')
return table
def get_company(self, code, full_codes):
op = ''
if len(code) == 8:
op = code[6] + code[7]
elif len(code) == 9:
op = code[6] + code[7] + code[9]
comp = full_codes.get(op)
if comp is None:
comp = full_codes.get('Default')
print(comp)
return comp
def give_me_business_class(self, decoded_code_bar, full_codes):
# Getting the right company to replace the with the good option
company = self.get_company(decoded_code_bar[2], full_codes)
case = decoded_code_bar[4]
julian_date = case[0] + case[1] + case[2]
classe = case[3]
seat = case[4] + case[5] +case[6] + case[7]
print('Actual Company :' + company.get('name'))
print('Business Class for this company : ' + company.get('business'))
print('\nActual classe : ' + classe)
print('Actual seat : ' + seat)
classe = company.get('business')
# Seat is currently 003B because business class is often within first numbers
seat = '003B'
print('\nNew classe : ' + classe)
print('New seat : ' + seat)
# Reformat to string
seq = ''
business = seq.join(decoded_code_bar)
return business
def create_codebar_from_data(self, business_code_bar):
outpath = self.abs_path + 'static/modified/' + self.uid + '-modified.png '
print('---> outpath : ' + outpath)
os.system('pdf417gen encode -o ' + outpath + '"' + business_code_bar + '"')
return
def get_updated_filepath(self):
return 'modified/' + self.uid + '-modified.png'
def fly(self):
full_codes = self.get_yaml()
if full_codes is not None:
decoded_code_bar = self.decode_this()
business_code_bar = self.give_me_business_class(decoded_code_bar, full_codes)
self.create_codebar_from_data(business_code_bar)