python variables in html / wordpress on cpanel hosting - python

I have a website that I am busy working on, which is a wordpress website that is on cpanel hosting.
The customer has some python programs that output information, which he would like to display on the website. EG, he has a program that gets some data from a few other websites, and does a bunch of calculations, and then returns a total. He would like to display that total on the website.
I was told I can put the .py file onto the server, but I am not sure how to get the output onto the wordpress page, or even an html page.
The one program has about 6 different variables it outputs, and he would like to display all 6 of the figures on the website.
All the searches I am doing are showing how to output html from a python file, which is not what I want. The website exists already, and so does the python scripts. I just want to put the information from the script onto the web page.
Any help would be greatly appreciated

Related

Using Python to scrape data from a websites HTML

I have used many of the popular libraries to read html and saw variations on this website but have had no success. I go to a website, call it www.google.com. I enter passwords and I am still at www.google.com. While in this website after using my password, I hit the F12 key to view the html. Inside the html, I see a number that changes at a rate of about 2Hz. This number is also on the webpage. I want to record this changing value over a period of time. I have tried to view that page using Python and my result is a new login page of the same name. I am currently using an OCR system but it is slow and it sometimes gets an incorrect value. This website is a service that I pay a little to use. I can send a request for the value but they get angry because the site cannot handle the multiple requests. Is there a way for me to simple read the html file in Python? I have tried to use Python to open the site but it sees it as not a person.

Running a Python Program in the backend on an HTML button click

I am developing a location based web app/website. The website involves an HTML webpage, which has a button which when clicked by the user should:
Extract the user location coordinates
Run a python Program whose input will be the extracted user location, perform some manipulation.
Finally display real-time results back to the html webpage/ i.e. user computer screen.
The python Program is currently accepting the user location by using geocoder function. The program is successfully running on my system/PC.
I have an AWS EC2 Ubuntu server, to which the location of the vehicle GPS device is being sent.
Finally once everything is set up, I will be hosting/deploying the website so that individual users can test it on their system. I am aware of the hosting part.
Can someone please tell me how do I get along with the task of running the python program on an HTML button click and sending back real time results (which is the output of the python program) back to the html webpage?
To run python code on a buttonClick, you can set a href attribute to a link, which you catch in your flask backend. For example <a href="http://myapp/runthiscode"/> in the HTML and app.rout("/runthiscode") in flask. After that, the manipulation, you can give the updated variables to the page, by redirecting with redirect("/", args=args). args are the updated variables, which you can use in the HTML. For example like this: <a> {{ args }} </a>
The simplest way I can think of doing this is creating a basic API endpoint to do this data processing and return it to your frontend.
The process will look like:
User clicks button
Grab the user's longitutde and latitude (most likely using this, though from the sounds you might be able to do this already)
Submit a POST request to your Flask backend
Render the response in the frontend
Jonas answer gives you a rough sense of what this would look like; the only thing I would add is a tutorial. This one from FreeCodeCamp looks great.

Can I manipulate an image in the browser with github pages?

Is it possible to upload and manipulate a photo in the browser with GitHub-pages? The photo doesn't need to be stored else than just for that session.
PS. I'm new to this area and I am using python to manipulate the photo.
GitHub pages allows users to create static HTML sites. This means you have no control over the server which hosts the HTML files - it is essentially a file server.
Even if you did have full control over the server (e.g. if you hosted your own website), it would not be possible to allow the client to run Python code in the browser since the browser only interprets JavaScript.
Therefore the most easy solution is to re-write your code in JavaScript.
Failing this, you could offer a download link to your Python script, and have users trust you enough to run it on their computer.

Any way to run web scripts from html, that browser runs automaticaly on page download?

I'm practicing in parsing web pages with python. So what I do is
ans = requests.get(link)
Then I use re to extract some information from html, that is stored in
ans.content
What I faced is that some sites use scripts, that are automatically executed in a browser, but not when I try to download a page using requests. For example, instead of getting a page with information I get something like
scripts_to_get_info.run()
in html code
Browser is installed on my computer, so as a program that I wrote, this means that, theoretically, I should have a way to run this script and to get information while running python code to parse then.
Is it possible? Any suggestion?
(idea, that this is doable, came from the fact, that when I tried to inspect page in google, I saw real html file without any trashy scripts)

How can one create an open web interface to a Python script that accepts and returns text?

I have a Python script that accepts text from a user, interprets that text and then produces a text response for that user. I want to create a simple web interface to this Python script that is accessible to multiple people at once. By this I mean that person A can go to the website for the script and begin interacting with the script and, at the same time, person B can do the same. This would mean that the script is running in as many processes/sessions as desired.
What would be a good way to approach this?
Maybe you should try a python web framework like django or flask .etc
Make a simple website that offers a webpage that contians a form to input text ,and when people visit the url, put their text in the form and submit, your code can handle it and return a webpage to show the result.

Categories