0

I was curious about this. I don't need code examples per se, I just want to know if my logic is correct.

As a very very basic example let's say I have a Python program running on my local machine and a website hosted with GoDaddy or some other host.

In my py file I have a basic variable like

x = 5

And on the website, there's user input such as a text/submit box. When a user inputs a number and submits, the python variable above will update to that new number.

What is the most efficient way of doing this? Would I utilize a database that stores the user input, and on a timed loop make the Python program query that db and update the variable accordingly or is there a more efficient/standard way of going about this?

I apologize if it's a dumb question, I haven't been able to find anything online so maybe my search engine skills need to be progressed.

  • First consider what resources the two different code-bases will/can share. A program running locally probably can't connect to the remote database reliably. This is often circumvented by preventing some form of 'Web API'. Then it's a matter of defining the contracts. As far as polling vs streaming, that's largely been solved with long polling (and various extensions to such). Of course, perhaps polling every 10 seconds is fine? That's a business logic choice. – user2864740 Jul 22 '21 at 21:06
  • @user2864740 thanks for the response! When you say the program can't connect to the db reliably, can you elaborate? Does using something like mysql.connector within Python have reliability issues connecting to a web hosted database? – Jason Rowls Jul 22 '21 at 21:08
  • Ah, reliability - database permission issues and network/security grants. If the local program has access, then the it is more likely someone else remote could also have access. It's usually more customary to hide the access and domain. – user2864740 Jul 22 '21 at 21:10
  • As far are 'needing' to pull, there are alternatives: https://ably.com/blog/websockets-vs-long-polling , https://stackoverflow.com/questions/35473356/is-there-any-javascript-tcp-soket-library-for-php-like-signalr-with-net etc. – user2864740 Jul 22 '21 at 21:12

1 Answers1

0

Having two websites built on different languages is cannot or should not be run in the same folder. The best you can do is to let them communicate through APIs.

Ezekiel Arin
  • 115
  • 6
  • The OP didn't ask about (or even mentioned) having two web sites in the same folder. They are literally asking about having one web site hosted on GoDaddy and then having a Python script locally. – M. Eriksson Jul 22 '21 at 22:20