How do I fetch and save files using JavaScript? - javascript

My goal is to create a program on a webpage. The program will Fetch an assembly folder. Then extract CNC files from the assembly folder and put the CNC files into one folder and sort the CNC files into 3 other folders (plywood, aluminum, or steel) based upon the filament type metadata in the CNC files.
What is the best method to doing this using JavaScript?
Is there a way to detect file properties such as whether a file is a CNC using JavaScript?
I was also thinking of incorporating Python, since JavaScript is too simple a language for this type of process. Is there a way to link JavaScript and Python, such that JavaScript will be the main class and Python will be used as a subclass(es)?
Thank you!

In, short you can't. It is not possible to do this using JavaScript in the browser. It is entirely possible to do this using Node.js. You can also certainly call Python from JavaScript and vice versa in Node. So to answer your questions:
The best method is using Node.js if you want to use JavaScript.
It depends on what you mean by "file properties". If you mean the EXIF data, then you can use a package called exif-parser or something similar. Maybe you want the MIME type of the file, if so then use mime-types. There's bound to be a package that you can utilize to achieve your needs.
It is possible to run JavaScript from Python and vice versa, but why? Both languages are more than capable on their own.

Related

Extensions in vs code

I have a question. I used vs code for python and I used some extensions for python like the python extension from microsoft. I currently want to use vs code for html,css and javascript. Does the pythons extensions affect my work in other languages and html and css? Do I need to disable them?
No. Extensions for languages are usually associated with a file type (.py, .css, etc.).
If the extentions you want to install in vscode dont depened on each other they will have seperated inner routines and frameworks. So no "collisions" or anything like that. In case of python you can have different environments per projects which can be tricky to handle. To learn more about that have a look at pyvenv or virtual environment.
It will have no effect, you don't need to disable it, because the extension only runs if you use a file format with .py
If your files are separated with their respective file type names attached (i.e. .css, .scss, .sass, .html, .py) the extensions designed for Python would theoretically only affect the Python files. If it's a really bad extension with low reviews maybe it would have a bug, but this is highly doubtful if you stick to highly-rated plugins. Simple.
No, they will not anithing. Because they are build to execute just with python files then any file that doesn't have (.py) at the end it will not be affected.

ReactJS - check the existence of local file using Javascript

I need to check a particular software (built by us) has been installed to the Operating system. If not need to show a proper alert message.
As an alternative solution I'm going to do something like this
After installing the software there will be file in a given path (ex: c:\mysoftware\config.txt)
If there is any way to to check the existence of this config.txt file from Javascript then I can create a function like isSoftwareInstalled() in my reactjs application.
Am i doing right thing? or is there any professional but simple way of doing this?
As far as I understand, you must be keeping this file somewhere on the server.
If you are using Node/Express in the backend, you can use the Node File System readFile method.
https://nodejs.dev/learn/reading-files-with-nodejs
If you use some other backend language, kindly use File API in that.
In case, you are wondering about client-side file read, this is not possible with JS.

Simple local folder file count to create a for loop based on elements contained

As simple as it is and as newbee I am, I fail to find a simple answer to that.
In my html index I need to create a loop based on the number of files with extension .obj of a folder in the same directory ..assets . grab the number of files with this extension and use it for a for loop. What would be the code?
Thank you in advance.
Unless you are talking about NodeJS, JavaScript runs (in a sandbox) on the CLIENT so it is not possible to do what you want. You would have to use a server side technology such as Ruby, Python, PHP etc.

How to automatically generate TypeScript files using JavaScript files and their test cases?

AFAIK, there is no tool which automatically converts JavaScript files into TypeScript files with meaningful information (e.g. accurate type annotations other than any for all). If given JavaScript files and their test cases, is it possible to generate the better quality of TypeScript files? For example, I can imagine one can modify a JavaScript engine to dynamically annotate the original JavaScript files by running test cases.
All javascript files are valid typescript files. So there wouldn't be anything to convert.
The closest thing I could think of would be something that could read javascript annotations and use those to create a typescript files (which would just be the javascript file with variable types included).
Here is some information regarding annotations since it seems to be on topic for this questions. JS Annotations

file layout and setuptools configuration for the python bit of a multi-language library

So we're writing a full-text search framework MongoDb. MongoDB is pretty much javascript-native, so we wrote the javascript library first, and it works.
Now I'm trying to write a python framework for it, which will be partially in python, but partially use those same stored javascript functions - the javascript functions are an intrinsic part of the library. On the other hand, the javascript framework does not depend on python. since they are pretty intertwined it seems like it's worthwhile keeping them in the same repository.
I'm trying to work out a way of structuring the whole project to give the javascript and python frameworks equal status (maybe a ruby driver or whatever in the future?), but still allow the python library to install nicely.
Currently it looks like this: (simplified a little)
javascript/jstest/test1.js
javascript/mongo-fulltext/search.js
javascript/mongo-fulltext/util.js
python/docs/indext.rst
python/tests/search_test.py
python/tests/__init__.py
python/mongofulltextsearch/__init__.py
python/mongofulltextsearch/mongo_search.py
python/mongofulltextsearch/util.py
python/setup.py
I've skipped out a few files for simplicity, but you get the general idea; it' a pretty much standard python project... except that it depends critcally ona whole bunch of javascript which is stored in a sibling directory tree.
What's the preferred setup for dealing with this kind of thing when it comes to setuptools? I can work out how to use package_data etc to install data files that live inside my python project as per the setuptools docs.
The problem is if i want to use setuptools to install stuff, including the javascript files from outside the python code tree, and then also access them in a consistent way when I'm developing the python code and when it is easy_installed to someone's site.
Is that supported behaviour for setuptools? Should i be using paver or distutils2 or Distribute or something? (basic distutils is not an option; the whole reason I'm doing this is to enable requirements tracking) How should i be reading the contents of those files into python scripts?
The short answer is that none of the Python distribution tools is going to do what you want, the exact way you want it. Even if you use distutils' data_files feature, you're still going to have to have your javascript files copied into your Python project directory (i.e., somewhere under the same directory as your setup.py.)
Given that, you might as well just copy the .js files to your package (i.e. alongside mongofulltextsearch/init.py) as part of your build process, and use package_data or include_package_data=True.
(Or alternatively, you could possibly use symlinks, externals, or some such, if your revision control system supports those. I believe that when building source distributions, the Python distribution tools convert symlinks to real files. At least, you could give that a try.)

Categories

Resources