|
|
@ -15,12 +15,12 @@ p.add_argument("--ask", "-a", metavar='',
|
|
|
|
args = p.parse_args()
|
|
|
|
args = p.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
site = Site(host=args.host, path=args.path)
|
|
|
|
site = Site(host=args.host, path=args.path)
|
|
|
|
|
|
|
|
|
|
|
|
wd = os.path.dirname(os.path.abspath(__file__)) # working directory
|
|
|
|
wd = os.path.dirname(os.path.abspath(__file__)) # working directory
|
|
|
|
imgdir = os.path.join(wd, 'images')
|
|
|
|
imgdir = os.path.join(wd, 'images')
|
|
|
|
imgsjson_fn = os.path.join(wd, 'images.json')
|
|
|
|
imgsjson_fn = os.path.join(wd, 'images.json')
|
|
|
|
with open(imgsjson_fn, 'r') as imgsjson_file:
|
|
|
|
with open(imgsjson_fn, 'r') as imgsjson_file:
|
|
|
|
images_info = json.load(imgsjson_file)
|
|
|
|
images_info = json.load(imgsjson_file)
|
|
|
|
|
|
|
|
|
|
|
|
static_html = os.path.join(wd, 'static_html')
|
|
|
|
static_html = os.path.join(wd, 'static_html')
|
|
|
|
os.makedirs(static_html, exist_ok=True) # create images/ dir
|
|
|
|
os.makedirs(static_html, exist_ok=True) # create images/ dir
|
|
|
|
|
|
|
|
|
|
|
@ -29,8 +29,6 @@ with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
|
|
|
|
user, pwd = loginlines.split('\n')
|
|
|
|
user, pwd = loginlines.split('\n')
|
|
|
|
site.login(username=user, password=pwd) # login to wiki
|
|
|
|
site.login(username=user, password=pwd) # login to wiki
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(os.path.join(wd, 'templates/publication.html')) as pub_html:
|
|
|
|
with open(os.path.join(wd, 'templates/publication.html')) as pub_html:
|
|
|
|
pub_template = Template(pub_html.read())
|
|
|
|
pub_template = Template(pub_html.read())
|
|
|
|
|
|
|
|
|
|
|
@ -39,9 +37,6 @@ with open(os.path.join(wd, 'templates/publication_part.html')) as pub_html:
|
|
|
|
|
|
|
|
|
|
|
|
pub_parts_html = '' # to append all content
|
|
|
|
pub_parts_html = '' # to append all content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for answer in site.ask(args.ask):
|
|
|
|
for answer in site.ask(args.ask):
|
|
|
|
publication_title = ''
|
|
|
|
publication_title = ''
|
|
|
|
# print(answer, answer.keys())
|
|
|
|
# print(answer, answer.keys())
|
|
|
@ -50,11 +45,11 @@ for answer in site.ask(args.ask):
|
|
|
|
img_info = images_info[printout_dict['page']]
|
|
|
|
img_info = images_info[printout_dict['page']]
|
|
|
|
page = site.pages[[printout_dict['page']]]
|
|
|
|
page = site.pages[[printout_dict['page']]]
|
|
|
|
pagetext = page.text()
|
|
|
|
pagetext = page.text()
|
|
|
|
# TODO: fix pandoc conversion
|
|
|
|
pagetext_html = pandoc(pwd=wd, content=pagetext, format_in='mediawiki', format_out='html')
|
|
|
|
pagetext_html = pagetext # pandoc(content=pagetext, format_in='mediawiki', format_out='html')
|
|
|
|
print(pagetext_html)
|
|
|
|
img_local = os.path.join(imgdir, img_info.get('filename'))
|
|
|
|
img_local = os.path.join(imgdir, img_info.get('filename'))
|
|
|
|
# pprint(img_info)
|
|
|
|
# pprint(img_info)
|
|
|
|
print(img_local)
|
|
|
|
# print(img_local)
|
|
|
|
pub_part_html = pub_part_template.render(
|
|
|
|
pub_part_html = pub_part_template.render(
|
|
|
|
imgsrc=os.path.join(imgdir, img_info.get('filename')),
|
|
|
|
imgsrc=os.path.join(imgdir, img_info.get('filename')),
|
|
|
|
text=pagetext_html,
|
|
|
|
text=pagetext_html,
|
|
|
@ -73,62 +68,8 @@ for answer in site.ask(args.ask):
|
|
|
|
with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile:
|
|
|
|
with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile:
|
|
|
|
htmlfile.write(pub_html)
|
|
|
|
htmlfile.write(pub_html)
|
|
|
|
|
|
|
|
|
|
|
|
print(pub_html, '\n')
|
|
|
|
# print(pub_html, '\n')
|
|
|
|
pub_parts_html = '' # Reset pub_parts_html
|
|
|
|
pub_parts_html = '' # Reset pub_parts_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: queries wihout Part?
|
|
|
|
#
|
|
|
|
# TODO: include Creator Property value
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# page_html_template = '''
|
|
|
|
|
|
|
|
# <!DOCTYPE html>
|
|
|
|
|
|
|
|
# <html lang="en">
|
|
|
|
|
|
|
|
# <head>
|
|
|
|
|
|
|
|
# <meta charset="utf-8">
|
|
|
|
|
|
|
|
# <link rel="stylesheet" href="../static/style.css" />
|
|
|
|
|
|
|
|
# <title>{{title}}</title>
|
|
|
|
|
|
|
|
# </head>
|
|
|
|
|
|
|
|
# <body>
|
|
|
|
|
|
|
|
# <h1>{{ title }}</h1>
|
|
|
|
|
|
|
|
# <p><time datetime="{{date}}">{{date}}</time></p>
|
|
|
|
|
|
|
|
# <div id="img">
|
|
|
|
|
|
|
|
# <img src="{{ imgsrc }}" />
|
|
|
|
|
|
|
|
# </div>
|
|
|
|
|
|
|
|
# <div id="content">
|
|
|
|
|
|
|
|
# {{ content }}
|
|
|
|
|
|
|
|
# </div>
|
|
|
|
|
|
|
|
# <footer>
|
|
|
|
|
|
|
|
# Part {{part}} of {{partof}}
|
|
|
|
|
|
|
|
# </footer>
|
|
|
|
|
|
|
|
# </body>
|
|
|
|
|
|
|
|
# </html>
|
|
|
|
|
|
|
|
# '''
|
|
|
|
|
|
|
|
# page_template = Template(page_html_template)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# for img_info in images_info.values():
|
|
|
|
|
|
|
|
# print(img_info)
|
|
|
|
|
|
|
|
# page_name = img_info['name']
|
|
|
|
|
|
|
|
# page = site.pages[page_name]
|
|
|
|
|
|
|
|
# # print(page)
|
|
|
|
|
|
|
|
# # pprint(page.__dict__)
|
|
|
|
|
|
|
|
# # print(dir(page))
|
|
|
|
|
|
|
|
# pagetext = page.text()
|
|
|
|
|
|
|
|
# pageproperties = page_props(wikicontent=pagetext)
|
|
|
|
|
|
|
|
# print(pageproperties)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# if pageproperties.get('Title'):
|
|
|
|
|
|
|
|
# pagetext_html = pandoc(content=pagetext, format_in='mediawiki', format_out='html')
|
|
|
|
|
|
|
|
# # print('pagetext', pagetext)
|
|
|
|
|
|
|
|
# # print('pagetext_html', pagetext_html)
|
|
|
|
|
|
|
|
# page_html = page_template.render(title=pageproperties.get('Title'),
|
|
|
|
|
|
|
|
# date=pageproperties.get('Date'),
|
|
|
|
|
|
|
|
# imgsrc=os.path.join(imgdir, img_info.get('filename')),
|
|
|
|
|
|
|
|
# content=pagetext_html,
|
|
|
|
|
|
|
|
# part=pageproperties.get('Part'),
|
|
|
|
|
|
|
|
# partof=pageproperties.get('Partof'))
|
|
|
|
|
|
|
|
# htmlpage_fn = "{}_{}.html".format(
|
|
|
|
|
|
|
|
# pageproperties.get('Title').replace(" ", ""),
|
|
|
|
|
|
|
|
# pageproperties.get('Part').zfill(3)
|
|
|
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
# print(htmlpage_fn)
|
|
|
|
|