{{ article.title }}
+ +No articles found.
+ {% endfor %} +diff --git a/joomla-export/.gitignore b/joomla-export/.gitignore new file mode 100644 index 00000000..8129f3e8 --- /dev/null +++ b/joomla-export/.gitignore @@ -0,0 +1,14 @@ +# Log files +*.log + +# Compiled/virtual environment files +*.pyc +*.pyo +*.exe +*.dll +*.egg +*.egg-info + +# Hidden files (starting with a dot) +.* +/venv/ diff --git a/joomla-export/MANIFEST.in b/joomla-export/MANIFEST.in new file mode 100644 index 00000000..84a8c883 --- /dev/null +++ b/joomla-export/MANIFEST.in @@ -0,0 +1 @@ +include templates/*.html diff --git a/joomla-export/README.md b/joomla-export/README.md new file mode 100644 index 00000000..07dcc49c --- /dev/null +++ b/joomla-export/README.md @@ -0,0 +1 @@ +# Export d'articles depuis Joomla diff --git a/joomla-export/index.py b/joomla-export/index.py new file mode 100644 index 00000000..b580ee9e --- /dev/null +++ b/joomla-export/index.py @@ -0,0 +1,86 @@ + +import pymysql +from jinja2 import Environment, FileSystemLoader +from flask import Flask, render_template +import os + +# Configuration +HOST = "localhost" +USER = "demoUser" +PASSWORD = "demoPassword" +DATABASE = "cijliness" +CHARSET = 'utf8mb4' + +# Initialize Flask app and Jinja2 template engine + + +app = Flask(__name__, template_folder=os.path.abspath('./templates')) + +app.config['TEMPLATES_AUTO_RELOAD'] = True +app.config['SECRET_KEY'] = 'your_secret_key' + +loader = FileSystemLoader('templates') +env = Environment(loader=loader) +app.jinja_env = env + +def get_formatted_date(value): + """Custom Jinja2 date filter.""" + return value.strftime("%Y-%m-%d %H:%M") + +env.filters['date'] = get_formatted_date + +def get_articles(): + """Fetch articles from the database.""" + try: + connection = pymysql.connect( + host=HOST, + user=USER, + password=PASSWORD, + db=DATABASE, + charset=CHARSET + ) + + cursor = connection.cursor() + + query = ''' + SELECT id, title, introtext,created FROM cijliness.cijl_content + WHERE state = 1 AND featured = 1 + ORDER BY created ASC + LIMIT 5000; + ''' + + cursor.execute(query) + + articles = [] + + for row in cursor: + articles.append({ + 'id': row[0], + 'title': row[1], + 'introtext': row[2], + 'created': row[3], + }) + + cursor.close() + connection.commit() + connection.close() + + return articles + + except pymysql.MySQLError as e: + print(f"Error: {e}") + return None +@app.route("/") +def index(): + """Render base.html with articles.""" + print(os.getcwd()) + articles = get_articles() + + if articles is not None: + context = {'articles': articles} + return render_template('base.html', **context) + + return "Failed to fetch articles." + +if __name__ == "__main__": + app.run() \ No newline at end of file diff --git a/joomla-export/requirements.txt b/joomla-export/requirements.txt new file mode 100644 index 00000000..a0b3f942 --- /dev/null +++ b/joomla-export/requirements.txt @@ -0,0 +1,3 @@ +Jinja2==3.1.4 +MarkupSafe==2.1.5 +PyMySQL==1.1.1 diff --git a/joomla-export/templates/base.html b/joomla-export/templates/base.html new file mode 100644 index 00000000..06bdff8c --- /dev/null +++ b/joomla-export/templates/base.html @@ -0,0 +1,40 @@ + + +
+ + +No articles found.
+ {% endfor %} +