0

My question is really simpel, but I haven't found it yet.

I have a python script running on my server. This script reads NFC cards. (pyscard) Everytime when there is a card the cardID must send to a webpage. I have in index.html file on my localhost.

<head>
  <title>Hello!</title>
</head>
   <script language="JavaScript" type="text/javascript">
   function card(Cardid){
     alert(Cardid);
   }
   </script>
<body>
</body>
</html>

There is a way to do it by selenium (driver.execute_script(command) ) Selenium is to heavy. Is there a other simple and light way to do this?

Wouter van Reeven
  • 517
  • 3
  • 8
  • 16
  • You just want to evaluate JavaScript using pyhon? If you don't want to use Selenium, try PyQt4, it's another alternative, or if you need to do it dynamically, follow the answer from @cleg – Vor Feb 11 '13 at 21:26

2 Answers2

1

If I got you right, you need to implement AJAX. Here is simpliest example How to implement a minimal server for AJAX in Python?

If you'll need something more complex — chose one of the python web frameworks (Flask or Django) and look for tutorials how to implement AJAX with them.

Community
  • 1
  • 1
cleg
  • 4,862
  • 5
  • 35
  • 52
0

If you want to push cardId to webpage you need tot use something in between like socket.IO then on a listening channel pushing the data to all websocket clients. From there you can pass it to a function like yours.

The other way to do it is a bit more limiting. You can make Ajax call to python which reads current card holding data and use that id. But when another card is on the reader,you then have tot refresh to see the new cards data.

Patrick
  • 51
  • 1
  • 2