'Passing' values from python script to javascript (locally) - javascript

I am trying to create/improve a microscope stage tracking system. So far I have written a python code (based on an old matlab one) which takes input from a webcam and uses it to calculate the position of the camera (and thus the stage). I now need to work out how to 'pass' data (an x and y position) to an xml file (which acts as the user interface) where certain positions can be saved etc.
Currently the python script constantly updates a text file, which is then constantly read by the xml file, but I'm wondering if there is a better solution. It has been suggested to me that I create a simple, local 'web server' to host the data, but I can only find information on how to host files which would seem to defeat the purpose...
Is there an easier way of doing this? Ive used python a decent amount (mainly for the numpy and scipy packages), but have little to no experience with web servers or xml...
Thanks
edit: I think this is the relevant part?
function getStagePos(xId,yId){
stagePosStr=getFromServer("file:///c:/stagePos.txt");
if(stagePosStr.substr(0,1)!="!"){
data=stagePosStr.split(",");
document.getElementById(xId).value=data[1];
document.getElementById(yId).value=data[2];
process();
}else{
warningNode.innerHTML="Stage Position too inaccurate";
window.setTimeout('warningNode.innerHTML=""',1000);
}
edit2: sorry for not being clear, this is the 'function' of the xml file (written in javascript?) which (I think) is reading in the two fields from the stagepos.txt file. Currently,this txt file is being updated by a matlab script which I have rewritten (and improved) using python. What I am trying to ask is if there is a way to update the two fields that appear when I open the xml file (which is used to save them at certain values to 'mark' locations on the stage) without first saving them to a text file?
edit3: re: changing tag from python to javascript: the code I posted is from the xml file (didnt realise It was javascript..) but my question relates to a python script which generates two constantly updating (at 30fps) fields and how to 'output' them to this file

Related

Obfuscate entire html or JavaScript on server side before sending to visitor

I want to obfuscate a entire page html or some specific JavaScript(which changes every minute), because lot of people are grabbing my html page and extracting a specific part of my JavaScript and using it.
I tried Dean Adward Packer http://joliclic.free.fr/php/javascript-packer/en/
But it still shows few things that are not to be extracted.
For Example: If i give this input with php.
var
abc="aaaaaaa=1111111111111&bbbbbb=2222222222222&ccccccc=33333333333333";
It is giving a following output
eval(function(p,a,c,k,e,d){e=function(c){return
c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return
d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new
RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('7
6="5=4&3=2&1=0";',8,8,'33333333333333|ccccccc|2222222222222|bbbbbb|1111111111111|aaaaaaa|abc|var'.split('|'),0,{}))
Here, anyone can observe all the values and extract using php code.
I am aware of some online obfuscators like SmartGB, JSFuck and Javasciptobfuscator.
These tools are perfect for my case, but i am not able use them on server side.
I also know that, all above obfuscations can be easily cracked, But there is no use of cracking it once. Because, a variable of JavaScript keeps on changing every time.
All i want to do here is preventing people from automatically extracting a variable value with a simple machine code on their webserver. But manually, we cant prevent anything as javascript is public.

Is it possible to use javascript to set the return value of an html file called from a batch file?

In Win7, I want to pass an arbitrary integer as the return code or Errorlevel from an HTML/Javascript file back to the batch file that started it.
Is there some way I can use javascript in the HTML program to set the return or Errorlevel code?
Edit:
WooHoo! Thanks! Yeah, my IE executes the sample HTA code.
That leaves the question of how I can manipulate the Errorlevel code from out of javascript in an hta program. The wikipedia blurb says I can control the system from an hta file, but javascript doesn't seem to have any commands to do so, even though hta allows it.
I still feel like one of those paralyzed 'locked-in' patients who have to communicate by trying to blink their eyes.

Read and Write DOCX file

I have 2 docx files that I am working with. One docx file contains text information of a product (start serial number, length, width, and height). The other docx file contains a sticker label with an image and all of the text information from the first file.
This is what I do currently:
I open the first docx file and copy all of the text information (serial, length, width, and height)
Then I paste each info into the second docx file that contains the formatted label.
If I need to make more than one label, I copy the label and increment the serial number by 1.
This takes a lot of time to make several labels for different products. My goal is to come up with an easier way to take data from one docx and inject it into the other. Also, generating more labels when needed.
My first thought was to extract the docx file to get it's xml contents. Then read the data using javascript, c++, or any other language. Then Ask user to input number of labels to generate, manipulate the xml, and repack it as a docx file.
Then I thought about trying to use the windows office "mail merge" feature, but I have never done this before.
I would like to know if anyone has any suggestions for an easy solution to import data from one docx file and generating labels into another.
I am open for any suggestion.
Also, I am not a professional programmer. I am an undergraduate computer engineering student with some experience in c, c++, java, javascript, python, MIPS assembly, and php.
The only open-source (and probably easier to come by) solution I know know is:
http://poi.apache.org/
http://poi.apache.org/document/quick-guide-xwpf.html
This is a good bet when it comes to speed and it is free software.
But if you open a file, alter it and save it again - the result can be flaky: The formatting can be slightly off. At least in my tests with the pptx counterpart.
I reckon when you have user interaction (web page?) in order to create the document, you can build a small HTTP Api around the library.
There is also: http://www.docx4java.org/trac/docx4j - which I have not tested yet.
You can also go the C#/Redmond way: How do I create the .docx document with Microsoft.Office.Interop.Word?
The Interop (2nd Example in the first answer of the question above) way gives the best result when it comes to the accuracy of the formatting. Basically when you open a file with Interop - it will look the same when you alter and save it. But you cannot use this when interacting with a user - because it starts a separate MS Office process - and I would not count on this from my own user experience. But if you want to generate these files as a batch in a single user session - it will deliver a good result.
I cannot comment on the "OpenXML SDK" library described in the above SO question.
Wath about the Open XML https://www.youtube.com/watch?v=rMnEl6JZ7I8 and website developer http://openxmldeveloper.org/ .
On the site you found sdk for:
Open XML SDK for JavaScript: http://openxmldeveloper.org/wiki/w/wiki/open-xml-sdk-for-javascript.aspx. Demo: http://openxmldeveloper.org/blog/b/openxmldeveloper/p/openxmlsdkjs_demo.aspx
Open XML and Java http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2006/11/21/openxmlandjava.aspx
.Net Resources http://openxmldeveloper.org/resources/dotnet/m/cc/default.aspx

Writing to a file in JavaScript

I created a canvas and letting user draw many shapes (circle, rectangle etc). I'm storing information of each shape (x, y, w, h, r) in objects and storing them in an array! Now i have an array of all the shapes with all required information to redraw them. What i want is, when user clicks 'save' button, HTML code of the drawn shapes gets saved in an HTML file! I just need to create a .html file and write all the code for drawn shapes in that (hard-coded, in a canvas ofcourse). I've been looking for a method to create new files within JavaScript and write into them.. I thought it's going to be as simple as file reading writing in Java but i am unable to find any easy way to do that... as there are some permission issues and stuff like that! Kindly tell me what to do?
The first line of the page about Javascript on Wikipedia (http://en.wikipedia.org/wiki/JavaScript) is about your issue.
JavaScript is an interpreted computer programming language. As
part of web browsers, implementations allow client-side scripts to
interact with the user.
You can't create, open, remove, write or edit file with Javascript on the client-side.
Barring the use of HTML5, which isn't fully supported yet, you'll want to post the data to the server and then have the user download the file.
For example, you could convert your array to JSON, place the JSON inside a TextArea tag wrapped inside an HTML form, and then submit the form. The page on the server that receives the form posting could respond my downloading a file to the user's browser.
If you tell us a little bit more about what you want to accomplish, we might be able to provide better answers. Do you want to create HTML so that the data can be viewed in the browser? If so, then you can manipulate the existing document in JavaScript. Are you looking to have users save their data and submit it to you for review? If so, a SQL database might be more appropriate.
If you are on local and on windows, you can use FileSysemObject ActiveX, but I don't think it's you are looking for.

How Can I Read A Web Browser Hidden Document Value Using IWebBrowser2 In LabVIEW?

I've searched around the internet for a couple of hours and could not find anything related to what I'm trying to do. I wrote a HTML document that collects data from a user and stores it in a javascript array. This array is then joined together and stored as a string in a document which is hidden. Originally, I was going to transfer this string to a program I wrote in C#, but now I am using LabVIEW.
In C#, I used two simple lines of code to do what I wanted:
System.Windows.Forms.HtmlElement hidden = webBrowser1.Document.GetElementById("hiddenfield1");
List<latlng> data = formharvest.extract(hidden.GetAttribute("value"));
But now I cannot find a way to access the data that is in this hidden document. I'm using the IWebBrowser2 block to embed my HTML code in my VI. Any help would be greatly appreciated. Thank you for your time!
A solution would be to start a Web server in your LabVIEW program, and serve your HTML form from it. I suppose it wouldn't be too hard to retrieve form data then, but I haven't done such thing myself.
Here's an interesting discussion on this with sample code.
I'm not sure I really understand what you are doing above: in the C#, it looks like you are embedding an HTML-rendering engine in a Windows form (i.e. window).
You can embed .NET in your labview code and therefore you should be able to embed the same HTML rendering engine in a LabView VI, but you might consider changing your approach, as CharlesB suggests, to something more traditional where a server serves some HTML to a web browser, which then sends some data back to the server via HTTP GET or POST.

Categories