From 04e82c720604dcbfd3d152ea5369b611e03a342a Mon Sep 17 00:00:00 2001 From: Sandra Date: Wed, 1 Apr 2020 19:17:54 +0200 Subject: [PATCH] publish cat --- dumpwiki.py | 29 +++++++++---- templates/default.html | 15 +++++++ templates/document1.html | 91 ++++++++++++++++++++++++++++++++++++++++ templates/document2.html | 84 +++++++++++++++++++++++++++++++++++++ templates/format.html | 17 ++++++++ templates/title.html | 86 ++++--------------------------------- 6 files changed, 235 insertions(+), 87 deletions(-) create mode 100644 templates/default.html create mode 100644 templates/document1.html create mode 100644 templates/document2.html create mode 100644 templates/format.html diff --git a/dumpwiki.py b/dumpwiki.py index 03182d3..601d692 100644 --- a/dumpwiki.py +++ b/dumpwiki.py @@ -45,8 +45,7 @@ with open('login.txt', 'r') as login: # read login user & pwd # read template files -with open('templates/title.html') as title_html: - title_template = Template(title_html.read()) + SLASH = "\u2044" @@ -54,13 +53,25 @@ def filenameforpage(p): f=p.name.replace(' ','_').replace('/', SLASH) + '.html' return f -title=site.Categories['Title'] -for p in title.members(): - print(p) - htmlsrc = site.parse(page=p.name)['text']['*'] - with open(os.path.join(args.output, filenameforpage(p)), 'w') as f: - print(htmlsrc, file=f) - # break +publish=site.Categories['Publish'] +for cat in publish.members(): + if cat.namespace!=14: + continue + print('dumping category {}'.format(cat.page_title)) + # title=site.Categories['Title'] + try: + with open('templates/{}.html'.format(cat.page_title.lower())) as templatefile: + template = Template(templatefile.read()) + except FileNotFoundError: + with open('templates/default.html') as templatefile: + template = Template(templatefile.read()) + for p in cat.members(): + print(p) + htmlsrc = site.parse(page=p.name)['text']['*'] + html = template.render(page=p, body=htmlsrc) + with open(os.path.join(args.output, filenameforpage(p)), 'w') as f: + print(html, file=f) + # break diff --git a/templates/default.html b/templates/default.html new file mode 100644 index 0000000..e6c9cbf --- /dev/null +++ b/templates/default.html @@ -0,0 +1,15 @@ + + + + + + + {{ page.name }} + + + +

{{ page.name }}

+
{{ body|safe }}
+ + + diff --git a/templates/document1.html b/templates/document1.html new file mode 100644 index 0000000..744b06a --- /dev/null +++ b/templates/document1.html @@ -0,0 +1,91 @@ + + + + + + + {{ title[0] }} + + +

{{ title[0] }}

+

+ +
+

Metadata

+
+
+ + + + + + + + + + +
+ + + + + + +
+ Title +
+ +
+ Date +
+ + + + + +
+ +
+ + + +
+ + + +
+

+

+
+ + + + {% for row in imgsmatrix %} +
+ {% for img in row %} +
+ +
+ {% endfor %} +
+ {% endfor %} + + + + +{# +
+
+ +
+
+ +
+
+ +
+
+ +
+
+#} \ No newline at end of file diff --git a/templates/document2.html b/templates/document2.html new file mode 100644 index 0000000..285e757 --- /dev/null +++ b/templates/document2.html @@ -0,0 +1,84 @@ + + + + + + + {{ title[0] }} + + +

{{ title[0] }}

+

+ + + +
{{ creator }}
+ +
{{ format }}
+ +
{{topic}}
+ + + + +
+ Title +
+ +
+ Date + Creator + Format + Topic +
+ + + + + +
+ +
+ + + +
+ + + +
+

+

+
+ + + + {% for row in imgsmatrix %} +
+ {% for img in row %} +
+ +
+ {% endfor %} +
+ {% endfor %} + + + + +{# +
+
+ +
+
+ +
+
+ +
+
+ +
+
+#} \ No newline at end of file diff --git a/templates/format.html b/templates/format.html new file mode 100644 index 0000000..cbc09cb --- /dev/null +++ b/templates/format.html @@ -0,0 +1,17 @@ + + + + + + + + + {{ page.name }} + + + +

{{ page.name }}

+
{{ body|safe }}
+ + + diff --git a/templates/title.html b/templates/title.html index 9785cb3..cbc09cb 100644 --- a/templates/title.html +++ b/templates/title.html @@ -2,86 +2,16 @@ - - - {{ title[0] }} + + + + + {{ page.name }} - -

{{ title[0] }} ↵

-

+ -
- -
- - - -
- -
- - -
- -
- - -
- -
- - -
-
+

{{ page.name }}

+
{{ body|safe }}
- - - - - - - - - - -
-

-

-
- - - - {% for row in imgsmatrix %} -
- {% for img in row %} -
- -
- {% endfor %} -
- {% endfor %} - -