![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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. ![]() |
|
|
|
|
|
#2 | |
|
Programmer
Join Date: Dec 2005
Posts: 65
Rep Power: 3
![]() |
Quote:
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 ![]() |
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
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()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. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|