first try at gemlog
This commit is contained in:
parent
a664c2beda
commit
96002f70b0
3 changed files with 64 additions and 1 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
!blog/index.gen.py
|
||||||
|
blog/
|
60
blog/index.gen.py
Executable file
60
blog/index.gen.py
Executable file
|
@ -0,0 +1,60 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
''' fetch (almost) all blog posts from Dotclear database and export them in Markdown format '''
|
||||||
|
''' TODO: use rss/atom feed instead '''
|
||||||
|
''' TODO: convert to proper Gemtext '''
|
||||||
|
|
||||||
|
import html2markdown
|
||||||
|
import mysql.connector
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
path_regex = re.compile('\d+/\d+/\d+')
|
||||||
|
date_regex = re.compile('\d+-\d+-\d+')
|
||||||
|
filename_regex = re.compile('\d+/\d+/\d+/(.*)')
|
||||||
|
|
||||||
|
db_password_regex = re.compile("'DC_DBPASSWORD','(.*)'")
|
||||||
|
db_host_regex = re.compile("'DC_DBHOST','(.*)'")
|
||||||
|
db_name_regex = re.compile("'DC_DBNAME','(.*)'")
|
||||||
|
db_user_regex = re.compile("'DC_DBUSER','(.*)'")
|
||||||
|
|
||||||
|
f = open("/home/www/dotclear/inc/config.php", "r")
|
||||||
|
c = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
mydb = mysql.connector.connect(
|
||||||
|
host=db_host_regex.findall(c)[0],
|
||||||
|
user=db_user_regex.findall(c)[0],
|
||||||
|
password=db_password_regex.findall(c)[0],
|
||||||
|
database=db_name_regex.findall(c)[0]
|
||||||
|
)
|
||||||
|
mycursor = mydb.cursor()
|
||||||
|
mycursor.execute("SELECT post_url, post_title, post_content_xhtml FROM dc_post WHERE post_url LIKE '%/%/%/%' ORDER BY post_id DESC")
|
||||||
|
myresult = mycursor.fetchall()
|
||||||
|
|
||||||
|
f = open("index.gmi", "w")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
for x in myresult:
|
||||||
|
path = path_regex.findall(x[0])[0]
|
||||||
|
filename = filename_regex.findall(x[0])[0]
|
||||||
|
|
||||||
|
f = open("index.gmi", "a")
|
||||||
|
f.write("=> %s/%s.gmi %s %s\n" % (path, filename, path, x[1]))
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.makedirs(path)
|
||||||
|
except OSError:
|
||||||
|
print ("Creation of the directory %s failed" % path)
|
||||||
|
|
||||||
|
print("creating %s/%s.gmi" % (path,quote(filename)))
|
||||||
|
f = open("%s/%s.gmi" % (path,quote(filename)), "w")
|
||||||
|
f.write("# %s\n\n" % x[1])
|
||||||
|
f.write("Publié le %s\n\n" % path)
|
||||||
|
f.write(html2markdown.convert(x[2]))
|
||||||
|
f.write("\n\n=> /blog/ Retour au menu du blog")
|
||||||
|
f.close()
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
|
|
||||||
Have a sit and enjoy the following content:
|
Have a sit and enjoy the following content:
|
||||||
|
|
||||||
=> freebsd.gmi Installing vger on FreeBSD, using inetd and nginx
|
=> freebsd.gmi howto: installing vger on FreeBSD, using inetd and nginx
|
||||||
|
=> blog/ a markdown export of my www blog (experimental, buggy and furthermore, in French)
|
||||||
|
|
Loading…
Reference in a new issue