2020-04-10 00:08:51 +02:00
|
|
|
|
import csv
|
|
|
|
|
import json
|
2020-04-11 14:15:42 +02:00
|
|
|
|
import os
|
2020-04-11 17:55:36 +02:00
|
|
|
|
from glob import glob
|
2020-04-11 15:16:05 +02:00
|
|
|
|
from creole.rest_tools.clean_writer import rest2html
|
2020-04-11 14:15:42 +02:00
|
|
|
|
|
2020-06-26 15:21:50 +02:00
|
|
|
|
TITLE_PREFIX = "iDie ::"
|
2020-04-10 00:08:51 +02:00
|
|
|
|
|
|
|
|
|
sheet = csv.reader(open('slides.csv'))
|
|
|
|
|
|
|
|
|
|
keys = sheet.__next__()
|
|
|
|
|
|
2020-04-11 17:55:36 +02:00
|
|
|
|
# get_content will remove all files we use
|
|
|
|
|
# and in the end of the process, only orphans
|
|
|
|
|
# will remain
|
|
|
|
|
orphans = glob('slides/*.rst')
|
2020-04-11 14:15:42 +02:00
|
|
|
|
|
|
|
|
|
def get_content(slide, default):
|
|
|
|
|
if not slide: # Happens for home slide
|
|
|
|
|
slide = '_home'
|
2020-04-11 15:16:05 +02:00
|
|
|
|
filename = 'slides/{}.rst'.format(slide)
|
2020-04-11 17:55:36 +02:00
|
|
|
|
# Yes. This is a side effect. Sorry.
|
|
|
|
|
if filename in orphans:
|
|
|
|
|
orphans.remove(filename)
|
2020-04-11 14:15:42 +02:00
|
|
|
|
if not os.path.isfile(filename):
|
|
|
|
|
desc = default.strip()
|
2020-05-18 15:58:07 +02:00
|
|
|
|
# if desc:
|
|
|
|
|
# desc = "**תוכן זמני:** {}".format(desc)
|
2020-04-11 14:15:42 +02:00
|
|
|
|
open(filename, 'w').write(desc)
|
|
|
|
|
print('Created {}.'.format(filename))
|
2020-04-11 15:16:05 +02:00
|
|
|
|
return rest2html(open(filename).read())
|
2020-04-11 14:15:42 +02:00
|
|
|
|
|
2020-06-06 14:19:05 +02:00
|
|
|
|
def post_process(content):
|
|
|
|
|
"currently, only [עריכת-רשימות] is dealt with"
|
|
|
|
|
return content.replace('[עריכת-רשימות]',
|
|
|
|
|
"""<a class="notes-edit-button" title="עריכת הרשימות שלי" rel="modal:open" href="#notes-modal"><i class="fa fa-file-signature"></i></a>""")
|
|
|
|
|
|
2020-04-13 14:01:37 +02:00
|
|
|
|
def format_slide_param(key, value):
|
|
|
|
|
return format('data-{}="{}"'.format(
|
|
|
|
|
key.strip(), value.strip()))
|
|
|
|
|
|
|
|
|
|
def get_slide_params(d):
|
|
|
|
|
params = []
|
2020-05-24 18:20:55 +02:00
|
|
|
|
if d.get('real-id', '').strip():
|
|
|
|
|
params.append(format_slide_param('real-id', d['real-id']))
|
|
|
|
|
if d.get('real-title', '').strip():
|
|
|
|
|
params.append(format_slide_param('real-title', d['real-title']))
|
2020-04-13 14:01:37 +02:00
|
|
|
|
if d.get('theme', '').strip():
|
|
|
|
|
params.append(format_slide_param('theme', d['theme'].lower()))
|
|
|
|
|
if d.get('bg-image','').strip():
|
|
|
|
|
params.append(format_slide_param('background-image', d['bg-image']))
|
|
|
|
|
if d.get('bg-style','').strip().lower()=='tile':
|
|
|
|
|
params.append(format_slide_param('background-size', 'auto'))
|
|
|
|
|
params.append(format_slide_param('background-repeat', 'repeat'))
|
|
|
|
|
if d.get('bg-opacity','').strip():
|
|
|
|
|
params.append(format_slide_param('background-opacity', d['bg-opacity']))
|
2020-05-31 14:50:25 +02:00
|
|
|
|
if d.get('bg-position','').strip():
|
|
|
|
|
params.append(format_slide_param('background-position', d['bg-position']))
|
2020-04-13 14:01:37 +02:00
|
|
|
|
return ' '.join(params)
|
|
|
|
|
|
2020-04-11 14:15:42 +02:00
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
col_id = None
|
|
|
|
|
col = None
|
|
|
|
|
cols = []
|
2020-05-24 18:20:55 +02:00
|
|
|
|
real_title = ''
|
|
|
|
|
real_id = ''
|
2020-04-11 14:15:42 +02:00
|
|
|
|
for r in sheet:
|
|
|
|
|
d = dict(zip(keys,r))
|
|
|
|
|
if not d['slide'].strip(): # new column
|
|
|
|
|
if col is not None: # deal with previous col
|
|
|
|
|
col['has_slides'] = len(col['slides'])>0
|
|
|
|
|
cols.append(col)
|
|
|
|
|
col_id = d['column']
|
2020-06-06 14:19:05 +02:00
|
|
|
|
content = d['html'].strip() or get_content(col_id, d['description'])
|
2020-04-11 14:15:42 +02:00
|
|
|
|
col = {
|
|
|
|
|
'id': col_id,
|
|
|
|
|
'title': d['title'],
|
2020-04-13 14:01:37 +02:00
|
|
|
|
'params': get_slide_params(d),
|
2020-06-06 14:19:05 +02:00
|
|
|
|
'content': post_process(content),
|
2020-04-11 14:15:42 +02:00
|
|
|
|
'has_menu': False,
|
|
|
|
|
'slides': []}
|
|
|
|
|
else:
|
2020-05-24 18:20:55 +02:00
|
|
|
|
slide_id = '_'.join(filter(None, [col_id, d['slide']]))
|
2020-05-19 19:31:35 +02:00
|
|
|
|
headline = d['title']
|
|
|
|
|
if headline:
|
2020-05-24 18:20:55 +02:00
|
|
|
|
real_title = headline
|
|
|
|
|
real_id = slide_id
|
2020-05-19 19:31:35 +02:00
|
|
|
|
else:
|
2020-05-24 18:20:55 +02:00
|
|
|
|
headline = '{} (המשך)'.format(real_title)
|
2020-05-27 17:18:52 +02:00
|
|
|
|
if len(col['slides']):
|
|
|
|
|
col['slides'][-1]['next'] = slide_id
|
2020-05-24 18:20:55 +02:00
|
|
|
|
d['real-id'] = real_id;
|
|
|
|
|
d['real-title'] = real_title;
|
2020-06-06 14:19:05 +02:00
|
|
|
|
content = d['html'].strip() or get_content(slide_id, d['description'])
|
2020-04-11 14:15:42 +02:00
|
|
|
|
col['slides'].append({
|
|
|
|
|
'id': slide_id,
|
|
|
|
|
'title': d['title'],
|
2020-05-19 19:31:35 +02:00
|
|
|
|
'headline': headline,
|
2020-04-13 14:01:37 +02:00
|
|
|
|
'params': get_slide_params(d),
|
2020-04-11 14:15:42 +02:00
|
|
|
|
'has_menu': False,
|
2020-06-06 14:19:05 +02:00
|
|
|
|
'content': post_process(content)})
|
2020-04-11 14:15:42 +02:00
|
|
|
|
col['has_slides'] = len(col['slides'])>0
|
|
|
|
|
cols.append(col)
|
|
|
|
|
cols[0]['has_menu'] = True
|
|
|
|
|
cols[0]['menu'] = [{"id": c['id'], "title": c['title']} for c in cols[1:]]
|
|
|
|
|
|
2020-06-26 15:21:50 +02:00
|
|
|
|
json.dump({"title": cols[0]['title'], "columns": cols, "title_prefix": TITLE_PREFIX}, open('slides.json', 'w'), indent=4)
|
2020-04-11 14:15:42 +02:00
|
|
|
|
print('successfully wrote slides.json')
|
2020-04-11 17:55:36 +02:00
|
|
|
|
if orphans:
|
|
|
|
|
print('Note! The following rst files are not mentioned in the csv sheet (orphans):')
|
|
|
|
|
for f in sorted(orphans):
|
|
|
|
|
print(' {}'.format(f))
|
2020-04-11 14:15:42 +02:00
|
|
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
|
|
|
main()
|