Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
c28e50a103 |
2 changed files with 32 additions and 53 deletions
|
@ -1,23 +0,0 @@
|
||||||
name: lint
|
|
||||||
run-name: lint is launched by ${{ github.actor }}
|
|
||||||
on: [push]
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: lint
|
|
||||||
steps:
|
|
||||||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
|
|
||||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Forgejo!"
|
|
||||||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Create Python virtualenv
|
|
||||||
run: |
|
|
||||||
mkdir -p .cache
|
|
||||||
python -m venv .
|
|
||||||
source bin/activate
|
|
||||||
XDG_CACHE_HOME=.cache pip install pylint-venv pylint
|
|
||||||
- name: Lint
|
|
||||||
run: XDG_CACHE_HOME=.cache ./bin/pylint -d E0401 blog/*.py
|
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
'''fetch (almost) all blog posts from Dotclear database and export them in Markdown format
|
''' fetch (almost) all blog posts from Dotclear database and export them in Markdown format '''
|
||||||
TODO: use rss/atom feed instead
|
''' TODO: use rss/atom feed instead '''
|
||||||
TODO: convert to proper Gemtext'''
|
''' TODO: convert to proper Gemtext '''
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import html2markdown
|
import html2markdown
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
path_regex = re.compile('\\d+/\\d+/\\d+')
|
path_regex = re.compile('\d+/\d+/\d+')
|
||||||
date_regex = re.compile('\\d+-\\d+-\\d+')
|
date_regex = re.compile('\d+-\d+-\d+')
|
||||||
filename_regex = re.compile('\\d+/\\d+/\\d+/(.*)')
|
filename_regex = re.compile('\d+/\d+/\d+/(.*)')
|
||||||
|
|
||||||
db_password_regex = re.compile("'DC_DBPASSWORD','(.*)'")
|
db_password_regex = re.compile("'DC_DBPASSWORD','(.*)'")
|
||||||
db_host_regex = re.compile("'DC_DBHOST','(.*)'")
|
db_host_regex = re.compile("'DC_DBHOST','(.*)'")
|
||||||
db_name_regex = re.compile("'DC_DBNAME','(.*)'")
|
db_name_regex = re.compile("'DC_DBNAME','(.*)'")
|
||||||
db_user_regex = re.compile("'DC_DBUSER','(.*)'")
|
db_user_regex = re.compile("'DC_DBUSER','(.*)'")
|
||||||
|
|
||||||
with open("/home/www/dotclear/inc/config.php", "r", encoding="utf-8") as f:
|
f = open("/home/www/dotclear/inc/config.php", "r")
|
||||||
c = f.read()
|
c = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
mydb = mysql.connector.connect(
|
mydb = mysql.connector.connect(
|
||||||
host=db_host_regex.findall(c)[0],
|
host=db_host_regex.findall(c)[0],
|
||||||
|
@ -28,36 +30,36 @@ mydb = mysql.connector.connect(
|
||||||
database=db_name_regex.findall(c)[0]
|
database=db_name_regex.findall(c)[0]
|
||||||
)
|
)
|
||||||
mycursor = mydb.cursor()
|
mycursor = mydb.cursor()
|
||||||
mycursor.execute("SELECT post_url, post_title, post_content_xhtml \
|
mycursor.execute("SELECT post_url, post_title, post_content_xhtml FROM dc_post WHERE post_url LIKE '%/%/%/%' ORDER BY post_id DESC")
|
||||||
FROM dc_post WHERE post_url LIKE '%/%/%/%' ORDER BY post_id DESC")
|
|
||||||
myresult = mycursor.fetchall()
|
myresult = mycursor.fetchall()
|
||||||
mydb.close()
|
|
||||||
|
|
||||||
with open("index.gmi", "w", encoding="utf-8") as f:
|
f = open("index.gmi", "w")
|
||||||
f.write("# Tourmentine's blog-to-gemlog\n\n")
|
f.write("# Tourmentine's blog-to-gemlog\n\n");
|
||||||
|
f.close()
|
||||||
|
|
||||||
for x in myresult:
|
for x in myresult:
|
||||||
path = path_regex.findall(x[0])[0]
|
path = path_regex.findall(x[0])[0]
|
||||||
path_with_dashes = path.replace("/","-")
|
filename = filename_regex.findall(x[0])[0]
|
||||||
title = filename_regex.findall(x[0])[0]
|
|
||||||
filename = re.sub(r'\W+','', title)
|
|
||||||
|
|
||||||
with open("index.gmi", "a", encoding="utf-8") as f:
|
f = open("index.gmi", "a")
|
||||||
f.write(f'=> {path}/{filename}.gmi {path_with_dashes} - {x[1]}\n')
|
f.write("=> %s/%s.gmi %s - %s\n" % (path, quote(quote(filename)), path.replace("/","-"), x[1]))
|
||||||
|
f.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
print (f"Creation of the directory {path} failed")
|
print ("Creation of the directory %s failed" % path)
|
||||||
|
|
||||||
if not os.path.isfile(f'{path}/{filename}.gmi'):
|
if not os.path.isfile('%s/%s.gmi' % (path,quote(filename))):
|
||||||
print(f"creating {path}/{filename}.gmi")
|
print("creating %s/%s.gmi" % (path,quote(filename)))
|
||||||
with open(f'{path}/{filename}.gmi', "w", encoding="utf-8") as f:
|
f = open("%s/%s.gmi" % (path,quote(filename)), "w")
|
||||||
f.write(f"# {x[1]}\n\n")
|
f.write("# %s\n\n" % x[1])
|
||||||
f.write(f"Publié le {path}\n\n")
|
f.write("Publié le %s\n\n" % path)
|
||||||
f.write(html2markdown.convert(x[2]))
|
f.write(html2markdown.convert(x[2]))
|
||||||
f.write("\n\n=> /blog/ Retour au menu du blog")
|
f.write("\n\n=> /blog/ Retour au menu du blog")
|
||||||
|
f.close()
|
||||||
|
|
||||||
with open("index.gmi", "a", encoding="utf-8") as f:
|
f = open("index.gmi", "a")
|
||||||
f.write("\n=> Retour")
|
f.write("\n=> Retour")
|
||||||
|
f.close()
|
||||||
|
|
Loading…
Reference in a new issue