From 959576ad96a5a7a53cb9b9f6c5e5fbb6ecff1bda Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Wed, 27 May 2020 01:14:11 +0200 Subject: Remove circular dependency on makefile --- bin/Makefile | 18 +++++++ bin/cleaner.py | 62 ++++++++++++++++++++++ bin/export.py | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+) create mode 100644 bin/Makefile create mode 100755 bin/cleaner.py create mode 100755 bin/export.py (limited to 'bin') diff --git a/bin/Makefile b/bin/Makefile new file mode 100644 index 00000000..10ac0d1e --- /dev/null +++ b/bin/Makefile @@ -0,0 +1,18 @@ +all: rebuild nikola build + +rebuild: + rm -rf git dump + ./export.py + rm git/pages/updates.md + +nikola: + venv/bin/nikola init -q git + cp site/conf.py git + cd git; nikola plugin -i localsearch + cd git; nikola theme -n ccc --parent=bootstrap4 + cp -r site/themes/ccc git/themes/ + cp -r site/data site/shortcodes git/ + cp -r site/index.rst site/index.en.rst site/search.html site/cpu site/themen git/pages/ + +build: + cd git; nikola build --backend=sqlite3 diff --git a/bin/cleaner.py b/bin/cleaner.py new file mode 100755 index 00000000..d8c999da --- /dev/null +++ b/bin/cleaner.py @@ -0,0 +1,62 @@ +#! venv/bin/python +import psycopg2 +import psycopg2.extras +import pathlib +import os.path +import datetime +import pypandoc +from bs4 import BeautifulSoup +from datetime import timedelta, datetime, tzinfo +#from langdetect import detect +import sys +import re + +conn = psycopg2.connect(database="cccms_dev", user="postgres", password="", host="127.0.0.1") +cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) + +cursor.execute("select * from page_translations") +page_translations = cursor.fetchall() + +fo = open("orig.txt", "w") +fm = open("modi.txt", "w") + +for translation in page_translations: + body = translation.get('body') + cursor.execute("select * from pages where id = %s", [translation['page_id']]) + page = cursor.fetchone() + + if not body: + continue + + if not '

\n\n") + + f.write(pypandoc.convert_text( str(translation.get('body', "")), 'markdown-smart', format='html-native_divs-native_spans', extra_args=['--atx-headers'])) + userrec = next(filter(lambda person: person['login'] == editor, user)) + page_list.append({ 'date': page['updated_at'], 'revision': page['revision'], 'comment': "page revision {}".format(page['revision']), 'fname': fname, 'gname': gitname, 'editor': editor, 'email': userrec['email']}) + +page_list.sort(key=lambda tup: (tup['date'], tup['revision'])) +for page in page_list: + print(page) + os.system("cp {} git/{}".format(page['fname'], page['gname'])) + os.system("git -C git/ add {}".format(page['gname'])) + os.environ['GIT_COMMITTER_NAME'] = page['editor'] + os.environ['GIT_COMMITTER_EMAIL'] = page['email'] + os.system('git -C git/ commit -m "committing {}" --author="{} <{}>" --date="{}"'.format(page['comment'], page['editor'], page['email'], page['date'])) + -- cgit v1.2.3