diff --git a/test.py b/test.py index 28ee24d..225e7b5 100644 --- a/test.py +++ b/test.py @@ -1,7 +1,9 @@ import os from flask import Flask, request, render_template, jsonify, redirect, url_for +import datetime # Import the datetime module app = Flask(__name__) + # Folder to store blog HTML files blog_folder = "blogs" if not os.path.exists(blog_folder): @@ -17,11 +19,19 @@ def create_blog(): blog_content = request.form['content'] author_name = request.form['author'] - # Store the blog in the JSON database + # Check if the date is provided in the form data + if 'date' in request.form: + blog_date = request.form['date'] + else: + # If no date is provided, use the default date "01/01/2023" + blog_date = '01/01/2023' + + # Store the blog in the JSON database along with the date blog = { 'title': blog_title, 'content': blog_content, - 'author': author_name + 'author': author_name, + 'date': blog_date # Use the provided date or the default date } blogs.append(blog) @@ -30,7 +40,7 @@ def create_blog(): html_path = os.path.join(blog_folder, html_filename) # Generate the HTML content and save it to the file - rendered_html = render_template('blog_template.html', blog_title=blog_title, author_name=author_name, blog_content=blog_content) + rendered_html = render_template('blog_template.html', blog_title=blog_title, author_name=author_name, blog_content=blog_content, date=blog_date) with open(html_path, 'w') as html_file: html_file.write(rendered_html) @@ -51,7 +61,7 @@ def blog(filename): @app.route('/blogquest') def blogquest(): - blog_data = [] + blog_entries = [] # Iterate through files in the "blogs" folder for filename in os.listdir(blog_folder): @@ -69,14 +79,33 @@ def blogquest(): if title_start != -1 and title_end != -1 and author_start != -1 and author_end != -1: blog_title = html_content[title_start:title_end] author_name = html_content[author_start:author_end] - blog_data.append({ - 'title': blog_title, - 'author': author_name, - 'url': f"/blog/{filename}" - }) - return render_template('blogquest.html', blogs=blog_data) + # Extract the date from the blog content (assuming a specific format) + date_start = html_content.find('
') + len('
') + date_end = html_content.find('
', date_start) + if date_start != -1 and date_end != -1: + blog_date = html_content[date_start:date_end] + else: + # Use the default date if no date is found + blog_date = '01/01/2023' + # Generate the HTML structure for each blog entry + entry_html = f""" +
+ E +
+
6
+ New! +
+ {blog_title}
+ In Gaming
+ By {author_name}
+
+ """ + + blog_entries.append(entry_html) + + return render_template('blogquest_template.html', blog_entries=blog_entries) if __name__ == '__main__': app.run(debug=True, port=8162)