Forms: Remove Cheogram boolean in favour of "Next".
Forms: Set title inside instructions field. ePUB: Use new keyword argument absolute_location from xml2epub.
This commit is contained in:
parent
85311edcf2
commit
b81ff04c0d
4 changed files with 48 additions and 45 deletions
|
@ -1410,6 +1410,7 @@ def generate_document(data, url, ext, filename, readability=False):
|
||||||
content = data
|
content = data
|
||||||
match ext:
|
match ext:
|
||||||
case "epub":
|
case "epub":
|
||||||
|
filename = filename.replace('.epub', '')
|
||||||
error = generate_epub(content, filename)
|
error = generate_epub(content, filename)
|
||||||
if error:
|
if error:
|
||||||
logger.error(error)
|
logger.error(error)
|
||||||
|
@ -1502,14 +1503,14 @@ async def extract_image_from_html(url):
|
||||||
return image_url
|
return image_url
|
||||||
|
|
||||||
|
|
||||||
def generate_epub(text, pathname):
|
def generate_epub(text, filename):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}: text: {} pathname: {}'.format(function_name, text, pathname))
|
logger.debug('{}: text: {} pathname: {}'.format(function_name, text, filename))
|
||||||
## create an empty eBook
|
## create an empty eBook
|
||||||
pathname_list = pathname.split("/")
|
filename_list = filename.split("/")
|
||||||
filename = pathname_list.pop()
|
file_title = filename_list.pop()
|
||||||
directory = "/".join(pathname_list)
|
directory = "/".join(filename_list)
|
||||||
book = xml2epub.Epub(filename)
|
book = xml2epub.Epub(file_title)
|
||||||
## create chapters by url
|
## create chapters by url
|
||||||
# chapter0 = xml2epub.create_chapter_from_string(text, title=filename, strict=False)
|
# chapter0 = xml2epub.create_chapter_from_string(text, title=filename, strict=False)
|
||||||
chapter0 = xml2epub.create_chapter_from_string(text, strict=False)
|
chapter0 = xml2epub.create_chapter_from_string(text, strict=False)
|
||||||
|
@ -1522,10 +1523,7 @@ def generate_epub(text, pathname):
|
||||||
# book.add_chapter(chapter1)
|
# book.add_chapter(chapter1)
|
||||||
# book.add_chapter(chapter2)
|
# book.add_chapter(chapter2)
|
||||||
## generate epub file
|
## generate epub file
|
||||||
filename_tmp = "slixfeedepub"
|
book.create_epub(directory, absolute_location=filename)
|
||||||
book.create_epub(directory, epub_name=filename_tmp)
|
|
||||||
pathname_tmp = os.path.join(directory, filename_tmp) + ".epub"
|
|
||||||
os.rename(pathname_tmp, pathname)
|
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = '0.1.44'
|
__version__ = '0.1.45'
|
||||||
__version_info__ = (0, 1, 44)
|
__version_info__ = (0, 1, 45)
|
||||||
|
|
|
@ -1095,6 +1095,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
title = sqlite.get_entry_title(db_file, ix)
|
title = sqlite.get_entry_title(db_file, ix)
|
||||||
title = title[0] if title else 'Untitled'
|
title = title[0] if title else 'Untitled'
|
||||||
form = self['xep_0004'].make_form('form', 'Article')
|
form = self['xep_0004'].make_form('form', 'Article')
|
||||||
|
form['instructions'] = title
|
||||||
url = sqlite.get_entry_url(db_file, ix)
|
url = sqlite.get_entry_url(db_file, ix)
|
||||||
url = url[0]
|
url = url[0]
|
||||||
logger.debug('Original URL: {}'.format(url))
|
logger.debug('Original URL: {}'.format(url))
|
||||||
|
@ -1109,7 +1110,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
else:
|
else:
|
||||||
summary = 'No content to show.'
|
summary = 'No content to show.'
|
||||||
form.add_field(ftype="text-multi",
|
form.add_field(ftype="text-multi",
|
||||||
label=title,
|
label='Article',
|
||||||
value=summary)
|
value=summary)
|
||||||
field_url = form.add_field(var='url',
|
field_url = form.add_field(var='url',
|
||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
|
@ -1139,7 +1140,6 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
options.addOption('Markdown', 'md')
|
options.addOption('Markdown', 'md')
|
||||||
options.addOption('PDF', 'pdf')
|
options.addOption('PDF', 'pdf')
|
||||||
options.addOption('Plain Text', 'txt')
|
options.addOption('Plain Text', 'txt')
|
||||||
form['instructions'] = 'Proceed to download article.'
|
|
||||||
session['allow_complete'] = False
|
session['allow_complete'] = False
|
||||||
session['allow_prev'] = True
|
session['allow_prev'] = True
|
||||||
session['has_next'] = True
|
session['has_next'] = True
|
||||||
|
@ -1188,6 +1188,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
session['notes'] = [['error', text_error]]
|
session['notes'] = [['error', text_error]]
|
||||||
else:
|
else:
|
||||||
url = await XmppUpload.start(self, jid_bare, filename)
|
url = await XmppUpload.start(self, jid_bare, filename)
|
||||||
|
chat_type = await get_chat_type(self, jid_bare)
|
||||||
|
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
||||||
form = self['xep_0004'].make_form('result', 'Download')
|
form = self['xep_0004'].make_form('result', 'Download')
|
||||||
form['instructions'] = ('Download {} document.'
|
form['instructions'] = ('Download {} document.'
|
||||||
.format(ext.upper()))
|
.format(ext.upper()))
|
||||||
|
@ -1265,8 +1267,13 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
session['payload'] = form
|
session['payload'] = form
|
||||||
# session['prev'] = self._handle_subscription_add
|
# session['prev'] = self._handle_subscription_add
|
||||||
elif result['error']:
|
elif result['error']:
|
||||||
response = ('Failed to load URL <{}> Reason: {} '
|
response = ('Failed to load resource.'
|
||||||
'(status code: {})'
|
'\n'
|
||||||
|
'URL {}'
|
||||||
|
'\n'
|
||||||
|
'Reason: {}'
|
||||||
|
'\n'
|
||||||
|
'Code: {}'
|
||||||
.format(url, result['message'], result['code']))
|
.format(url, result['message'], result['code']))
|
||||||
session['allow_prev'] = True
|
session['allow_prev'] = True
|
||||||
session['next'] = None
|
session['next'] = None
|
||||||
|
@ -1284,10 +1291,10 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
form['instructions'] = ('Subscription is already assigned at index {}.'
|
form['instructions'] = ('Subscription is already assigned at index {}.'
|
||||||
'\n'
|
'\n'
|
||||||
'{}'
|
'{}'
|
||||||
|
'\n'
|
||||||
|
'\n'
|
||||||
|
'Proceed to edit this subscription'
|
||||||
.format(result['index'], result['name']))
|
.format(result['index'], result['name']))
|
||||||
form.add_field(ftype='boolean',
|
|
||||||
var='edit',
|
|
||||||
label='Would you want to edit this subscription?')
|
|
||||||
form.add_field(var='subscription',
|
form.add_field(var='subscription',
|
||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
value=result['link'])
|
value=result['link'])
|
||||||
|
@ -1313,10 +1320,10 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
form['instructions'] = ('New subscription'
|
form['instructions'] = ('New subscription'
|
||||||
'\n'
|
'\n'
|
||||||
'"{}"'
|
'"{}"'
|
||||||
|
'\n'
|
||||||
|
'\n'
|
||||||
|
'Proceed to edit this subscription'
|
||||||
.format(result['name']))
|
.format(result['name']))
|
||||||
form.add_field(ftype='boolean',
|
|
||||||
var='edit',
|
|
||||||
label='Continue to edit subscription?')
|
|
||||||
form.add_field(var='subscription',
|
form.add_field(var='subscription',
|
||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
value=result['link'])
|
value=result['link'])
|
||||||
|
@ -1793,10 +1800,6 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if 'edit' in payload['values'] and not payload['values']['edit']:
|
|
||||||
session['payload'] = None
|
|
||||||
session['next'] = None
|
|
||||||
return session
|
|
||||||
if 'subscription' in payload['values']:
|
if 'subscription' in payload['values']:
|
||||||
urls = payload['values']['subscription']
|
urls = payload['values']['subscription']
|
||||||
elif 'subscriptions' in payload['values']:
|
elif 'subscriptions' in payload['values']:
|
||||||
|
@ -2320,13 +2323,13 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
for ext in exts:
|
for ext in exts:
|
||||||
filename = await action.export_feeds(self, jid_bare, jid_file, ext)
|
filename = await action.export_feeds(self, jid_bare, jid_file, ext)
|
||||||
url = await XmppUpload.start(self, jid_bare, filename)
|
url = await XmppUpload.start(self, jid_bare, filename)
|
||||||
|
chat_type = await get_chat_type(self, jid_bare)
|
||||||
|
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
||||||
url_field = form.add_field(var=ext.upper(),
|
url_field = form.add_field(var=ext.upper(),
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
label=ext,
|
label=ext,
|
||||||
value=url)
|
value=url)
|
||||||
url_field['validate']['datatype'] = 'xs:anyURI'
|
url_field['validate']['datatype'] = 'xs:anyURI'
|
||||||
chat_type = await get_chat_type(self, jid_bare)
|
|
||||||
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
|
||||||
form['type'] = 'result'
|
form['type'] = 'result'
|
||||||
form['title'] = 'Done'
|
form['title'] = 'Done'
|
||||||
form['instructions'] = ('Completed successfully!')
|
form['instructions'] = ('Completed successfully!')
|
||||||
|
|
|
@ -1055,6 +1055,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
title = sqlite.get_entry_title(db_file, ix)
|
title = sqlite.get_entry_title(db_file, ix)
|
||||||
title = title[0] if title else 'Untitled'
|
title = title[0] if title else 'Untitled'
|
||||||
form = self['xep_0004'].make_form('form', 'Article')
|
form = self['xep_0004'].make_form('form', 'Article')
|
||||||
|
form['instructions'] = title
|
||||||
url = sqlite.get_entry_url(db_file, ix)
|
url = sqlite.get_entry_url(db_file, ix)
|
||||||
url = url[0]
|
url = url[0]
|
||||||
logger.debug('Original URL: {}'.format(url))
|
logger.debug('Original URL: {}'.format(url))
|
||||||
|
@ -1069,7 +1070,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
else:
|
else:
|
||||||
summary = 'No content to show.'
|
summary = 'No content to show.'
|
||||||
form.add_field(ftype="text-multi",
|
form.add_field(ftype="text-multi",
|
||||||
label=title,
|
label='Article',
|
||||||
value=summary)
|
value=summary)
|
||||||
field_url = form.add_field(var='url',
|
field_url = form.add_field(var='url',
|
||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
|
@ -1099,7 +1100,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
options.addOption('Markdown', 'md')
|
options.addOption('Markdown', 'md')
|
||||||
options.addOption('PDF', 'pdf')
|
options.addOption('PDF', 'pdf')
|
||||||
options.addOption('Plain Text', 'txt')
|
options.addOption('Plain Text', 'txt')
|
||||||
form['instructions'] = 'Proceed to download article.'
|
|
||||||
session['allow_complete'] = False
|
session['allow_complete'] = False
|
||||||
session['allow_prev'] = True
|
session['allow_prev'] = True
|
||||||
session['has_next'] = True
|
session['has_next'] = True
|
||||||
|
@ -1148,6 +1148,8 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
session['notes'] = [['error', text_error]]
|
session['notes'] = [['error', text_error]]
|
||||||
else:
|
else:
|
||||||
url = await XmppUpload.start(self, jid_bare, filename)
|
url = await XmppUpload.start(self, jid_bare, filename)
|
||||||
|
chat_type = await get_chat_type(self, jid_bare)
|
||||||
|
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
||||||
form = self['xep_0004'].make_form('result', 'Download')
|
form = self['xep_0004'].make_form('result', 'Download')
|
||||||
form['instructions'] = ('Download {} document.'
|
form['instructions'] = ('Download {} document.'
|
||||||
.format(ext.upper()))
|
.format(ext.upper()))
|
||||||
|
@ -1225,8 +1227,13 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
session['payload'] = form
|
session['payload'] = form
|
||||||
# session['prev'] = self._handle_subscription_add
|
# session['prev'] = self._handle_subscription_add
|
||||||
elif result['error']:
|
elif result['error']:
|
||||||
response = ('Failed to load URL <{}> Reason: {} '
|
response = ('Failed to load resource.'
|
||||||
'(status code: {})'
|
'\n'
|
||||||
|
'URL {}'
|
||||||
|
'\n'
|
||||||
|
'Reason: {}'
|
||||||
|
'\n'
|
||||||
|
'Code: {}'
|
||||||
.format(url, result['message'], result['code']))
|
.format(url, result['message'], result['code']))
|
||||||
session['allow_prev'] = True
|
session['allow_prev'] = True
|
||||||
session['next'] = None
|
session['next'] = None
|
||||||
|
@ -1244,10 +1251,10 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
form['instructions'] = ('Subscription is already assigned at index {}.'
|
form['instructions'] = ('Subscription is already assigned at index {}.'
|
||||||
'\n'
|
'\n'
|
||||||
'{}'
|
'{}'
|
||||||
|
'\n'
|
||||||
|
'\n'
|
||||||
|
'Proceed to edit this subscription'
|
||||||
.format(result['index'], result['name']))
|
.format(result['index'], result['name']))
|
||||||
form.add_field(ftype='boolean',
|
|
||||||
var='edit',
|
|
||||||
label='Would you want to edit this subscription?')
|
|
||||||
form.add_field(var='subscription',
|
form.add_field(var='subscription',
|
||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
value=result['link'])
|
value=result['link'])
|
||||||
|
@ -1273,10 +1280,10 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
form['instructions'] = ('New subscription'
|
form['instructions'] = ('New subscription'
|
||||||
'\n'
|
'\n'
|
||||||
'"{}"'
|
'"{}"'
|
||||||
|
'\n'
|
||||||
|
'\n'
|
||||||
|
'Proceed to edit this subscription'
|
||||||
.format(result['name']))
|
.format(result['name']))
|
||||||
form.add_field(ftype='boolean',
|
|
||||||
var='edit',
|
|
||||||
label='Continue to edit subscription?')
|
|
||||||
form.add_field(var='subscription',
|
form.add_field(var='subscription',
|
||||||
ftype='hidden',
|
ftype='hidden',
|
||||||
value=result['link'])
|
value=result['link'])
|
||||||
|
@ -1753,10 +1760,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if 'edit' in payload['values'] and not payload['values']['edit']:
|
|
||||||
session['payload'] = None
|
|
||||||
session['next'] = None
|
|
||||||
return session
|
|
||||||
if 'subscription' in payload['values']:
|
if 'subscription' in payload['values']:
|
||||||
urls = payload['values']['subscription']
|
urls = payload['values']['subscription']
|
||||||
elif 'subscriptions' in payload['values']:
|
elif 'subscriptions' in payload['values']:
|
||||||
|
@ -2280,13 +2283,13 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
for ext in exts:
|
for ext in exts:
|
||||||
filename = await action.export_feeds(self, jid_bare, jid_file, ext)
|
filename = await action.export_feeds(self, jid_bare, jid_file, ext)
|
||||||
url = await XmppUpload.start(self, jid_bare, filename)
|
url = await XmppUpload.start(self, jid_bare, filename)
|
||||||
|
chat_type = await get_chat_type(self, jid_bare)
|
||||||
|
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
||||||
url_field = form.add_field(var=ext.upper(),
|
url_field = form.add_field(var=ext.upper(),
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
label=ext,
|
label=ext,
|
||||||
value=url)
|
value=url)
|
||||||
url_field['validate']['datatype'] = 'xs:anyURI'
|
url_field['validate']['datatype'] = 'xs:anyURI'
|
||||||
chat_type = await get_chat_type(self, jid_bare)
|
|
||||||
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
|
||||||
form['type'] = 'result'
|
form['type'] = 'result'
|
||||||
form['title'] = 'Done'
|
form['title'] = 'Done'
|
||||||
form['instructions'] = ('Completed successfully!')
|
form['instructions'] = ('Completed successfully!')
|
||||||
|
@ -2308,7 +2311,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
jid_full = str(session['from'])
|
jid_full = str(session['from'])
|
||||||
chat_type = await get_chat_type(self, jid_bare)
|
chat_type = await get_chat_type(self, jid_bare)
|
||||||
moderator = None
|
moderator = None
|
||||||
moderator = None
|
|
||||||
if chat_type == 'groupchat':
|
if chat_type == 'groupchat':
|
||||||
moderator = is_moderator(self, jid_bare, jid_full)
|
moderator = is_moderator(self, jid_bare, jid_full)
|
||||||
if chat_type == 'chat' or moderator:
|
if chat_type == 'chat' or moderator:
|
||||||
|
|
Loading…
Reference in a new issue