1

Hi fellow scriptwriters,

I have a python program that outputs data frequently but i would like to have this data displayed on a website automatically instead of manually doing so due to the large amount of data it is,

so the question is how do i do this? I have been finding conflicting information online but most of it insists i have to use an online server, I'm looking for confirmation that that can work before diving into new territory,

and if it does, can i connect the output from a server to automatically update a django webapp?

Thanks, Massive Love

Cave Man
  • 76
  • 2
  • 8

1 Answers1

2

Ok, there are few ways to do that.

The easiest I think would be a chain like this:

  1. your script generates a file
  2. the file is uploaded to the server (ie. over ftp or scp)
  3. when someone opens the website it reads the file and presents the results

If you don't already have a server here are some free hosting services that support python.

Here is an example of how to upload the file to the server. Simple text file might be enough for you, but if you have a lot of data than maybe a database of some sort could be better.

I don't know the nature of your data and the way you want it presented, but the website displaying it on the web could be as simple as reading line by line from the file and then printing it out with some rudimentary formating:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

with open('index.html') as data:
    for line in data:
        print "<p>%s</p>" % line

I know my answer doesn't have a lot of specifics but maybe it will point you into the right direction.

Rafał Gajda
  • 151
  • 6
  • HI Thanks for the reply. The script should run in the server i presume? the data i would like to be posted on the site every 3 minutes from the program, I think a some servers can handle that. – Cave Man May 09 '18 at 07:19
  • No problem. But the script doesn't have to run on the server. It can run on any machine with Internet connection and than just upload the file every 3 minutes (you can schedule it in cron for example). Or it can be placed on the server and scheduled there. If the server doesn't allow you to use scheduler to run scripts than you can make that script execute when someone visits a website. If it takes a long time to generate data you can make a separate site (from one showing results) that would trigger data generation and visit it every 3 min triggering it remotely. Possibilities are endless :) – Rafał Gajda May 09 '18 at 07:33
  • WOw, Awesome I'll research more on the technical side of it, Thanks you'r answers have been massive help – Cave Man May 10 '18 at 12:12