Add option to set message formatting.

Restore summary.
This commit is contained in:
Schimon Jehudah 2024-02-26 01:17:50 +00:00
parent bfde775369
commit b5e5a179f4
7 changed files with 62 additions and 48 deletions

View file

@ -186,12 +186,13 @@ async def xmpp_send_update(self, jid, num=None):
ix = result[0]
title_e = result[1]
url = result[2]
enclosure = result[3]
feed_id = result[4]
date = result[5]
summary = result[3]
enclosure = result[4]
feed_id = result[5]
date = result[6]
title_f = sqlite.get_feed_title(db_file, feed_id)
title_f = title_f[0]
news_digest += list_unread_entries(result, title_f)
news_digest += list_unread_entries(result, title_f, jid_file)
# print(db_file)
# print(result[0])
# breakpoint()
@ -408,7 +409,7 @@ def is_feed(feed):
return value
def list_unread_entries(result, feed_title):
def list_unread_entries(result, feed_title, jid_file):
# TODO Add filtering
# TODO Do this when entry is added to list and mark it as read
# DONE!
@ -428,29 +429,41 @@ def list_unread_entries(result, feed_title):
# NOTE Why doesn't this work without list?
# i.e. for result in results
# for result in results.fetchall():
ix = result[0]
title = result[1]
ix = str(result[0])
title = str(result[1])
# # TODO Retrieve summary from feed
# # See fetch.view_entry
# summary = result[2]
# # Remove HTML tags
# try:
# summary = BeautifulSoup(summary, "lxml").text
# except:
# print(result[2])
# breakpoint()
# # TODO Limit text length
summary = result[3]
# Remove HTML tags
try:
summary = BeautifulSoup(summary, "lxml").text
except:
print(result[3])
breakpoint()
# TODO Limit text length
# summary = summary.replace("\n\n\n", "\n\n")
# length = sqlite.get_setting_value(db_file, "length")
# summary = summary[:length] + " […]"
summary = summary.replace('\n', ' ')
summary = summary.replace(' ', ' ')
summary = summary.replace(' ', ' ')
db_file = config.get_pathname_to_database(jid_file)
length = config.get_setting_value(db_file, "length")
length = int(length)
summary = summary[:length] + " […]"
# summary = summary.strip().split('\n')
# summary = ["> " + line for line in summary]
# summary = "\n".join(summary)
link = result[2]
link = remove_tracking_parameters(link)
link = (replace_hostname(link, "link")) or link
news_item = ("\n{}\n{}\n{} [{}]\n").format(str(title), str(link),
str(feed_title), str(ix))
# news_item = ("\n{}\n{}\n{} [{}]\n").format(str(title), str(link),
# str(feed_title), str(ix))
formatting = config.get_setting_value(db_file, 'formatting')
news_item = formatting.format(feed_title=feed_title,
title=title,
summary=summary,
link=link,
ix=ix)
news_item = news_item.replace('\\n', '\n')
return news_item
@ -1207,6 +1220,7 @@ async def scan(db_file, url):
entry = {
"title": title,
"link": link,
"summary": summary,
"enclosure": media_link,
"entry_id": entry_id,
"date": date,

View file

@ -36,6 +36,9 @@ quantum = 3
# Pick random item from database
random = 0
# Set message formatting
formatting = {title}\n> {summary}\n{link}\n{feed_title} [{ix}]\n\n
# Utilized in case of missing protocol support.
[Bridge]
gopher =

View file

@ -52,15 +52,15 @@ def get_setting_value(db_file, key):
value = value[0]
else:
value = get_value("settings", "Settings", key)
try:
value = int(value)
except ValueError as e:
print('ValueError for value {} (key {}):\n{}'.format(value, key, e))
if isinstance(value, bool):
if value:
value = 1
else:
value = 0
# try:
# value = int(value)
# except ValueError as e:
# print('ValueError for value {} (key {}):\n{}'.format(value, key, e))
# if isinstance(value, bool):
# if value:
# value = 1
# else:
# value = 0
return value

View file

@ -77,11 +77,13 @@ def create_tables(db_file):
id INTEGER NOT NULL,
title TEXT NOT NULL,
link TEXT NOT NULL,
summary TEXT,
enclosure TEXT,
entry_id TEXT NOT NULL,
feed_id INTEGER NOT NULL,
timestamp TEXT,
read INTEGER NOT NULL DEFAULT 0,
reject INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY ("feed_id") REFERENCES "feeds" ("id")
ON UPDATE CASCADE
ON DELETE CASCADE,
@ -89,26 +91,19 @@ def create_tables(db_file):
);
"""
)
categories_table_sql = (
"""
CREATE TABLE IF NOT EXISTS categories (
id INTEGER NOT NULL,
name TEXT,
PRIMARY KEY ("id")
);
"""
)
entries_table_sql = (
"""
CREATE TABLE IF NOT EXISTS entries (
id INTEGER NOT NULL,
title TEXT NOT NULL,
link TEXT NOT NULL,
summary TEXT,
enclosure TEXT,
entry_id TEXT NOT NULL,
feed_id INTEGER NOT NULL,
timestamp TEXT,
read INTEGER NOT NULL DEFAULT 0,
reject INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY ("feed_id") REFERENCES "feeds" ("id")
ON UPDATE CASCADE
ON DELETE CASCADE,
@ -1000,11 +995,11 @@ async def get_unread_entries(db_file, num):
cur = conn.cursor()
sql = (
"""
SELECT id, title, link, enclosure, feed_id, timestamp
SELECT id, title, link, summary, enclosure, feed_id, timestamp
FROM entries
WHERE read = 0
UNION ALL
SELECT id, title, link, enclosure, feed_id, timestamp
SELECT id, title, link, summary, enclosure, feed_id, timestamp
FROM archive
ORDER BY timestamp DESC
LIMIT :num
@ -1541,14 +1536,15 @@ async def add_entries_and_update_timestamp(db_file, feed_id, new_entries):
"""
INSERT
INTO entries(
title, link, enclosure, entry_id, feed_id, timestamp, read)
title, link, summary, enclosure, entry_id, feed_id, timestamp, read)
VALUES(
:title, :link, :enclosure, :entry_id, :feed_id, :timestamp, :read)
:title, :link, :summary, :enclosure, :entry_id, :feed_id, :timestamp, :read)
"""
)
par = {
"title": entry["title"],
"link": entry["link"],
"summary": entry["summary"],
"enclosure": entry["enclosure"],
"entry_id": entry["entry_id"],
"feed_id": feed_id,

View file

@ -1,2 +1,2 @@
__version__ = '0.1.22'
__version_info__ = (0, 1, 22)
__version__ = '0.1.23'
__version_info__ = (0, 1, 23)

View file

@ -1373,7 +1373,7 @@ class Slixfeed(slixmpp.ClientXMPP):
else:
form['instructions'] = 'Adding subscription'
title = ''
tags = ''
tags = '' # TODO Suggest tags by element "categories"
form.add_field(ftype='fixed',
value='Properties')
form.add_field(var='name',
@ -1430,6 +1430,7 @@ class Slixfeed(slixmpp.ClientXMPP):
return session
# TODO Create a new form. Do not "recycle" the last form.
async def _handle_subscription_complete(self, payload, session):
jid = session['from'].bare
values = payload['values']

View file

@ -28,7 +28,7 @@ import logging
import os
import slixfeed.action as action
import slixfeed.config as config
from slixfeed.dt import current_time, timestamp
import slixfeed.dt as dt
import slixfeed.fetch as fetch
import slixfeed.sqlite as sqlite
import slixfeed.task as task
@ -557,7 +557,7 @@ async def message(self, message):
if not result['error']:
data = result['content']
code = result['status_code']
title = get_document_title(data)
title = action.get_document_title(data)
title = title.strip().lower()
for i in (' ', '-'):
title = title.replace(i, '_')
@ -1137,10 +1137,10 @@ async def message(self, message):
if not os.path.isdir(data_dir + '/logs/'):
os.mkdir(data_dir + '/logs/')
action.log_to_markdown(
current_time(), os.path.join(data_dir, 'logs', jid_file),
dt.current_time(), os.path.join(data_dir, 'logs', jid_file),
jid, message_text)
action.log_to_markdown(
current_time(), os.path.join(data_dir, 'logs', jid_file),
dt.current_time(), os.path.join(data_dir, 'logs', jid_file),
self.boundjid.bare, response)
print(