joomla export
This commit is contained in:
parent
01d3e713e9
commit
f1493a380d
|
@ -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/
|
|
@ -0,0 +1 @@
|
|||
include templates/*.html
|
|
@ -0,0 +1 @@
|
|||
# Export d'articles depuis Joomla
|
|
@ -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()
|
|
@ -0,0 +1,3 @@
|
|||
Jinja2==3.1.4
|
||||
MarkupSafe==2.1.5
|
||||
PyMySQL==1.1.1
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>My EBook</title>
|
||||
<!-- Add any CSS stylesheets or external resources here -->
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Welcome to My EBook</h1>
|
||||
<style type="text/css">
|
||||
body{
|
||||
width: 40rem;
|
||||
padding: 4rem;
|
||||
}
|
||||
|
||||
.article{
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
</style>
|
||||
</header>
|
||||
<main>
|
||||
{% for article in articles %}
|
||||
<section class="article">
|
||||
<h2><a href="#{{ loop.index }}" id="{{ loop.index }}">{{ article.title }}</a></h2>
|
||||
<time datetime="{{ article.created | date }}">
|
||||
Published {{ article.created | date }}
|
||||
</time>
|
||||
<div dangerouslySetInnerHTML={{ article.introtext|safe }}>
|
||||
{{ article.introtext }}
|
||||
</div>
|
||||
</section>
|
||||
{% else %}
|
||||
<p>No articles found.</p>
|
||||
{% endfor %}
|
||||
</main>
|
||||
<!-- Add any JavaScript scripts or external resources here -->
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue