Compare commits
No commits in common. "eea8c9f5fa8b007add0fb3bec518207783db7221" and "68b95bfe176950d7e0eae42e4e1eecbbf7430034" have entirely different histories.
eea8c9f5fa
...
68b95bfe17
11
Dockerfile
11
Dockerfile
@ -1,11 +0,0 @@
|
|||||||
FROM python:latest
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y libgl1-mesa-glx ghostscript && apt-get clean && rm -rf /var/lib/apt/lists
|
|
||||||
COPY . .
|
|
||||||
#COPY config-server.yml config.yml
|
|
||||||
RUN pip3 install -r requirements.txt
|
|
||||||
|
|
||||||
CMD ["python3", "run.py"]
|
|
||||||
EXPOSE 5000
|
|
||||||
EXPOSE 8000
|
|
||||||
EXPOSE 9000
|
|
@ -227,7 +227,7 @@ def get_multi(partnums):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
partnums = ["7958A", "10GXS12", "RST 5L-RKT 5L-949",
|
partnums = ["10GXS12", "RST 5L-RKT 5L-949",
|
||||||
"10GXS13",
|
"10GXS13",
|
||||||
"10GXW12",
|
"10GXW12",
|
||||||
"10GXW13",
|
"10GXW13",
|
||||||
|
@ -9,8 +9,6 @@ from PIL import Image
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
from util import fprint
|
from util import fprint
|
||||||
import uuid
|
|
||||||
from util import run_cmd
|
|
||||||
|
|
||||||
def parse(filename, output_dir, partnum):
|
def parse(filename, output_dir, partnum):
|
||||||
|
|
||||||
@ -165,75 +163,20 @@ def parse(filename, output_dir, partnum):
|
|||||||
|
|
||||||
previous_table = table_name
|
previous_table = table_name
|
||||||
|
|
||||||
# remove multi-line values that occasionally squeak through
|
|
||||||
def replace_newlines_in_dict(d):
|
|
||||||
for key, value in d.items():
|
|
||||||
if isinstance(value, str):
|
|
||||||
# Replace \n with " " if the value is a string
|
|
||||||
d[key] = value.replace('\n', ' ')
|
|
||||||
elif isinstance(value, dict):
|
|
||||||
# Recursively call the function if the value is another dictionary
|
|
||||||
replace_newlines_in_dict(value)
|
|
||||||
return d
|
|
||||||
|
|
||||||
tables = replace_newlines_in_dict(tables)
|
fprint(tables)
|
||||||
|
|
||||||
# summary
|
# summary
|
||||||
|
|
||||||
output_table = dict()
|
tables["partnum"] = partnum
|
||||||
output_table["partnum"] = partnum
|
with open(output_dir + "/tables.json", 'w') as json_file:
|
||||||
id = str(uuid.uuid4())
|
json.dump(tables, json_file)
|
||||||
output_table["id"] = id
|
|
||||||
#output_table["position"] = id
|
|
||||||
#output_table["brand"] = brand
|
|
||||||
output_table["fullspecs"] = tables
|
|
||||||
output_table["searchspecs"] = {"partnum": partnum, **flatten(tables)}
|
|
||||||
|
|
||||||
output_table["searchspecs"]["id"] = id
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print(output_table)
|
|
||||||
|
|
||||||
run_cmd("rm " + output_dir + "/*.json") # not reliable!
|
|
||||||
with open(output_dir + "/" + output_table["searchspecs"]["id"] + ".json", 'w') as json_file:
|
|
||||||
json.dump(output_table["searchspecs"], json_file)
|
|
||||||
|
|
||||||
return output_table
|
|
||||||
|
|
||||||
|
|
||||||
def flatten(tables):
|
return tables
|
||||||
def convert_to_number(s):
|
|
||||||
try:
|
|
||||||
# First, try converting to an integer.
|
|
||||||
return int(s)
|
|
||||||
except ValueError:
|
|
||||||
# If that fails, try converting to a float.
|
|
||||||
try:
|
|
||||||
return float(s)
|
|
||||||
except ValueError:
|
|
||||||
# If it fails again, return the original string.
|
|
||||||
return s
|
|
||||||
out = dict()
|
|
||||||
print("{")
|
|
||||||
for table in tables.keys():
|
|
||||||
for key in tables[table].keys():
|
|
||||||
if len(key) < 64:
|
|
||||||
keyname = key
|
|
||||||
else:
|
|
||||||
keyname = key[0:64]
|
|
||||||
|
|
||||||
fullkeyname = (table + ": " + keyname).replace(".","")
|
|
||||||
if type(tables[table][key]) is not tuple:
|
|
||||||
out[fullkeyname] = convert_to_number(tables[table][key])
|
|
||||||
print("\"" + keyname + "\":", "\"" + str(out[fullkeyname]) + "\",")
|
|
||||||
elif len(tables[table][key]) == 1:
|
|
||||||
out[fullkeyname] = convert_to_number(tables[table][key][0])
|
|
||||||
|
|
||||||
print("\"" + keyname + "\":", "\"" + str(out[fullkeyname]) + "\",")
|
|
||||||
|
|
||||||
print("}")
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
2
util.py
2
util.py
@ -123,7 +123,7 @@ class Logger(object):
|
|||||||
self.terminal = sys.stdout
|
self.terminal = sys.stdout
|
||||||
|
|
||||||
def write(self, message):
|
def write(self, message):
|
||||||
#self.log.write(message)
|
self.log.write(message)
|
||||||
#close(filename)
|
#close(filename)
|
||||||
#self.log = open(filename, "a")
|
#self.log = open(filename, "a")
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user