From fbd669f14a9cdf1d168549456b8e2ba1109bc919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Fri, 14 Apr 2023 10:27:02 +0200 Subject: [PATCH] init python export script --- main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..9752fc3 --- /dev/null +++ b/main.py @@ -0,0 +1,26 @@ +import pymysql +import os +import yaml + +# Connect to the MySQL database +db = pymysql.connect( + host='localhost', + db='spip', + user='spip', + password='password', +) + +# Query the database to retrieve all data +cursor = db.cursor() +cursor.execute('SELECT * FROM spip_articles') + +# Loop through the results and format data into Markdown files +for row in cursor.fetchall(): + front_matter = {'title': row[1], 'date': row[2]} # Example front matter fields + markdown_content = f'---\n{yaml.dump(front_matter)}---\n{row[3]}' # Example Markdown content + file_path = f'{row[0]}.md' # Example file path + with open(file_path, 'w') as f: + f.write(markdown_content) + +# Close the database connection +db.close()