Run script on a webhosting server - python

I built a website in plain HTML and CSS. For quicker modification of the contents in the HTML file, I wrote a python script to dynamically change the file (open file, write to it, close). Is it possible to run this script or an executable file on a web hosting server in order to modify the HTML file? (I know, it might not be the best approach to the problem).

Related

Python script to download directory from URL

I want to copy my own photos in a given web directory to my Raspberry so I can display them in a slideshow.
I'm looking for a "simple" script to download these files using python. I can then paste this code into my slideshow so that it refreshes the pics every day.
I suppose that the python wget utility would be the tool to use. However, I can only find examples on how to download a single file, not a whole directory.
Any ideas how to do this?
It depends on the server used to host the images and if the script can see a list of images to download. If this list isn't there in some form e.g. a webpage list, JSON or XML feed, there is no way for a script to download the files as the script doesnt "know" what's there dynamically.
Another option is for a python script to SSH into the server, list the contents of a directory and then download. This presumes you have programmatic access to the server.
If access to the server is a no, and there is no dynamic list then the last option would be to go to this website where you know the photos are and scrape their paths and download them. However this may scrape unwanted data such as other images, icons, etc.
https://medium.freecodecamp.org/how-to-scrape-websites-with-python-and-beautifulsoup-5946935d93fe

executing a python script in Django

I made a python script (a URL extractor with selenium)(myurl.py) and I want to print the output URL into an HTML button. I'm using Django.
If you use Djano I don't know why you ask about PHP, but:
You can save this output in file via Python and then get its content by PHP.
You can use database. By Python script save output to record, then display its by PHP
Of course it's possible only when you are executing python script on the server where website is installed

Running a python script on my hosting

I am a newbie to web development and Python. Since I dont have the vocabulary to ask the exact question, here is a summary of what need to do:
I have a small test python cgi script, which i have uploaded to /home/username/pyscripts which is above the /home/username/domain.com
I need a link I can type in the URL bar, which will lead to the script being executed and the content displayed in the browser.
Can someone tell me If i need to create an html file, and if yes how to get it to point to the python script The domain folder has wordpress installed. My hosting is dreamhost shared hosting
The script is there below:
#! /usr/bin/python
print 'Content-type: text/html'
print ''
print 'Hello, World!
Heroku is a good place to host and python scripts.
Pre-req
pythonscripts.py
procfile
requirements.txt
and After add, commit and push the scripts to heroku app. Just run the following command on terminal to run the scripts.
heroku run python your_scripts.py
More if you want to run this scripts on a schedule timing. then heroku provides lots of adds-on. just search it on heroku
Usually you'd need to put your python script under the /home/username/bin/ folder. I'm not sure if your particular webhost actually allows you to run your Python script outside of the /bin folder (normally this is not the case), but if yes then you can substitute the /pyscripts folder.
The URL would look something like this: www.domain.com/bin/mypythonscript.py
Or with the pyscripts folder (if possible with your webhost): www.domain.com/pyscripts/mypythonscript.py
You don't need to create an HTML file as the first content line that you print in your Python script is telling the user's browser to display the output of the script like an HTML file. You simply type the URL to your python script into your browser and then the server runs the script and outputs it as a text/HTML file, which your browser then reads and displays.
Also, don't forget - you need to grant execute/read/write permission to your Python script file after you upload it to the correct folder on your webhost server or it won't run at all. Usually this is done through your upload utility like Filezilla or using a shell command like chmod.
Well dream host support python. Check if they are providing shell access deployment. All you need is create .py file and run it.
Then consider to use Django or Jinja2 like framwork. Its easy for creating web application

Is it possible to run python in the web with github.io?

I want to run a python file in the web I have in a GitHub repository. Is it possible to do this?
And by running in the web, I mean putting #!/usr/bin/python and print 'Content-type:text/html\n in the first two lines.
In general this is not possible, Github (pages) serves only static content (ex: HTML, CSS, JS). If you want python to run (ex generate dynamic content) you need a web server capable of running python (your browser were the contents of GitHub Pages get downloaded and run can't do it).
That said there are experimental ways of running subsets of python in the browser. Take a look for a example at this question.
If you truly want to generate a complete HTTP response via standard output, then start by reading about CGI and Python's standard cgi module. You'll also need to have access to a CGI-compatible web server, perhaps running on a virtual host.
However, CGI is quite obsolescent as a way to produce dynamic output for the web. #jjwon's suggestion to look at Python-based web application frameworks like Flask is a good one.

Python with xampp

I want to create a .py file and display simple html code, just like I simply open any php file. I've put file.py inside of the c:/xampp/cgi-bin directory, I've enagled .py extension in apache configs, but...am I doing this the right way? What next?
How to open this file? localhost/cgi-bin/file.py displays the internal server 500 error with the note "Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4" at the bottom.
you need Choose a web framework. CherryPy. Pylons. Django.

Categories

Resources