Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Automating blog (http://www.programmingforums.org/showthread.php?t=7805)

thechristelegacy Jan 2nd, 2006 8:42 PM

Automating blog
 
I've been working on automating my personal blog lately. I just added a new comment system in php a while back and updating the blog is a daunting task which discourgaes me to make more updates. There is a lot of work put into just making one post. I need to insert a lot of information for file names in about four differnt places in three differnt files. Here is the way I have it set up.

-index.html (The actual blog.)
-monthdateyear.html (Each blog has a corrosponding comment page with that format)
-filewrite.php (The file I wrote to make the comments)

I already wrote a script that asks for the date and the filename I'd like to create, and it automaticly creates the comment page, but I'd also like to insert the dates and filenames directly into index.html and filewrite.php. I was ecen thinking about the script just letting me write the whole body of blog entry and then insert that also. In the end, once I'm done writing the body, it would let me double check it, and then I'll have it automaticly uploaded to my server via ftp.

The problem I have is with automaticly inserting the body and the links into the files. I was thinking about where the body of my blog starts (where all the posts go) putting a comment at the top that would, say <!--body--> and then somehow have Python recognize that, and everytime it sees it, it would place the body with all the links and dates from stored variables right into the page and then save it. What's the general idea of how I would go about doing this?

Also with the PHP file, are you able to put HTML comment tags directly into php, and if not, how would I be able to insert a date into my list of dates. Here is the code in question.
[php]
$pages = array('oct3105.html', 'nov1005.html', 'nov1705.html','nov2505.html','dec1025.html','dec2405.html');
if( in_array($filename, $pages) )
[/php]

What the array does is when the comment goes to be written, it can only write to files in this list so that poeple can enter in code in the URL and put stuff wherever. Everytime I update the blog, I have to go in and manually add in the file name. Is there a way I can have Python recognize that somehow and have it insert the stored date?

Any comments and replies are welcome. My thanks ahead of time. :D

para Jan 3rd, 2006 2:08 AM

Quote:

Originally Posted by thechristelegacy
I've been working on automating my personal blog lately. I just added a new comment system in php a while back and updating the blog is a daunting task which discourgaes me to make more updates. There is a lot of work put into just making one post. I need to insert a lot of information for file names in about four differnt places in three differnt files. Here is the way I have it set up.

I don't know much about PHP, or web design for that matter, but I find PHPBb to be an excellent system. I can't really answer your question though since I've never touched Python, but I recommend giving PHPBb a shot as being your backend, and writing a small frontend for grabbing information generated by it and displaying it on your page. With this you have all the neat little features of a full forum, but you can display it in a blog-like format. I recently used this approach for a devlog I started, works great.

http://www.phpbb.com/

-edit-
OH, you can also use the Smarty template engine ( http://smarty.php.net/ ) to help generate your output. Very nice stuff :)

Arevos Jan 3rd, 2006 5:17 AM

You can use C-style comments in PHP:
[php]$pages = array('oct3105.html', 'nov1005.html' /*@date */);[/php]And in Python you can easily replace a substring with something else, by using 'replace':
:

file = open("filewrite.php", "r")
file_contents = file.read()
file.close()
new_contents = file_contents.replace("/* @date */", new_date + "/* @date */");
file = open("filewrite.php", "w")
file.write(new_contents)
file.close()

However this might not be the best way to go about it. Usually, blogs store the comment and post data in a database or XML file, and then either generate the HTML on the fly, or to use caching and generate it only when the stored data is changed. Storing data directly to HTML is a bit of a headache, especially with user-created content.

There's also a lot of open source blogging software out there already. Just type "php blog" into Google and you'll see what I mean. Using off-the-shelf blogging systems might make it easier for you.

thechristelegacy Jan 3rd, 2006 7:29 AM

Thanks for the replies. Eventually I do want to move it to a database or XML file, but I need to do a lot more learning. I'm going to try Arevos's method when I return home from school today, it looks quite promissing for what I need.

Thanks again.


All times are GMT -5. The time now is 8:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC