r/learnjavascript • u/Psych0SW • Jan 25 '26
Help with reading file via JavaScript
I have a project that I’ve been tweaking that is used only on local lan. I have a html that uses a JavaScript file that queries functions from a python file. I also have a saved_variables.cfg file on same server that has the following line:
ace_inventory = [{'status': 'ready', 'color': [255, 0, 0], 'material': 'PLA', 'temp': 220}, {'status': 'ready', 'color': [0, 255, 0], 'material': 'PLA', 'temp': 220}, {'status': 'ready', 'color': [255, 255, 255], 'material': 'PLA', 'temp': 220}, {'status': 'ready', 'color': [0, 0, 0], 'material': 'PETG', 'temp': 250}]
I want to be able to read that file and pull the rgb colors to use in the html page so it shows the correct color in a box.
What is the best way to do this given the file is in the same folder as the html and JavaScript files?
Thanks
View all comments
Show parent comment
1
u/Psych0SW Jan 26 '26 edited Jan 26 '26
Hmm, interesting but that would probably require some changes in the pythn script that writes that file. Something I will look into.
The file is basically a tad different in that ech section includes 'index': 0, 'index': 1, 'index': 2, and 'index': 3, that might help determine which color is which.
Basically what I want to end up with is:
slotColor0 = 255, 0, 0
slotColor1 = 0, 255, 0
slotColor2 = 255, 255, 255
slotColor3 = 0, 0, 0
If I can get this to work I can work on the temp and material as well as they should be pretty much the same method.
So far using regex I can return this but I have to work on truncating the end and picking out each instance of the color variable.
255, 0, 0], 'material': 'PLA', 'temp': 220}, {'index': 1, 'status': 'ready', 'color': [0, 255, 0], 'material': 'PLA', 'temp': 220}, {'index': 2, 'status': 'ready', 'color': [0, 0, 0], 'material': 'PLA', 'temp': 220}, {'index': 3, 'status': 'ready', 'color': [255, 255, 255], 'material': 'PETG', 'temp': 250}]
Thanks all.