Automatically Update Content

Permalink 1 user found helpful
I would like to automatically update a content block every X hours by sending new data to my website from my local computer. I am gathering a live data stream and need to use python based tools to run analysis on it. Then I want to push that to the site. Is there any way I can ftp a file to the website and set up a job that runs periodically and updates the content block with the new data? Or is there some other good way of doing this?

Thanks for your help.

 
szucslaszlo replied on at Permalink Reply
I believe this page can get you started on the matter. In short: yes, you can do it - but unfortunately, I do not have any experience on the issue to give further hints.

http://www.concrete5.org/documentation/developers/system/jobs/...
jshannon replied on at Permalink Best Answer Reply
jshannon
It really depends on how fancy you want to get.

If you just want to use PHP and send up HTML encoded file (or not encoded at all), you can create a block that just includes a file (wouldn't be surprised if this already exists).

You could also create one that reads a table value, which your local script would be responsible for updating somehow (via SQL).

And/or you also create a tools file which will receive the data from your script and pop it into the db / file / whatever.
mesuva replied on at Permalink Reply
mesuva
Are you thinking of this James?
http://www.concrete5.org/marketplace/addons/file-reader/...

Another suggestion might be to use the RSS Displayer block. If you can upload some XML, or create a script (in the tools directory) that outputs XML, the RSS block can read and output it, periodically refreshing. The RSS block can have a feed URL that refers to a file on your site. (just a suggestion, this might be overkill, but this approach has worked really well for me a few times)
jakem replied on at Permalink Reply
Thanks for the help, the file reader block seems like the most straightforward option. I just uploaded an html file to the /tmp/file_name.html but it can't seem to find it. Any ideas?
mesuva replied on at Permalink Reply
mesuva
I'd suggest that's just a matter of getting your path correct.
/tmp/file_name.html wouldn't refer to the root of your website, it would refer to the absolute path on the server. Often it's something like:
/home/youraccountname/public_html/file.html

An easy way to find this is to create a new php file (something like test.php) on your server and put in it:
<?php echo $_SERVER["DOCUMENT_ROOT"]; ?>


That will tell you the document root and you can adjust the path to your file accordingly.
jakem replied on at Permalink Reply
That was it! Thanks so much!
jvansanten replied on at Permalink Reply
Sure.

One way to approach this might be an RSS feed -- as that functionality comes with the core system:http://www.concrete5.org/documentation/developers/helpers/rss-feeds... &http://simplepie.org/wiki/ .

Alternatively, here are some of the pieces needed to create the functionality yourself.

The linux cron daemon runs the crontab file where you can define the frequency at which a routine is to be run as well as the name of the routine:http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/...

Standard PHP can be used to open files on the file system.

The content of a specific block can be updated. You'll want the ID of the page as well as the ID of the block and find that in the appropriate C5 table. After updating, users will see the new content. Sorry I don't have specific code examples here.
mesuva replied on at Permalink Reply
mesuva
I wouldn't recommend updating the contents of a block by directly editing a record in the c5 database - it's a dangerous thing to do, and block IDs change as versions of pages are created. I don't think I'd ever recommend directly manipulating any concrete5 core table (that's what the API is for).

In these kind of cases, you want the block itself to do the retrieval of information, whether it's reading a flat file, fetching an RSS feed or reading a _custom_ database table.

I reckon jakem has this sorted out with goutnet's handy file reader block.