* Remove HTML tags from titles.
Fetch:
* Handle all exceptions.
SQLite:
* Add more functions to handle new ad-hoc commands.
Ad-Hoc:
* Move all commands into a single module called command.
* Remove commands from client and component.
Documentation:
* Comment commands that are not available.
This commit is contained in:
Schimon Jehudah 2024-02-29 17:08:53 +00:00
parent b5e5a179f4
commit 270551b8ee
9 changed files with 2325 additions and 3835 deletions

View file

@ -436,6 +436,7 @@ def list_unread_entries(result, feed_title, jid_file):
summary = result[3] summary = result[3]
# Remove HTML tags # Remove HTML tags
try: try:
title = BeautifulSoup(title, "lxml").text
summary = BeautifulSoup(summary, "lxml").text summary = BeautifulSoup(summary, "lxml").text
except: except:
print(result[3]) print(result[3])

View file

@ -17,18 +17,22 @@ opml = """
export opml export opml
Send an OPML file with feeds. Send an OPML file with feeds.
""" """
html = """
backup news html
Send an HTML formatted file of your news items.
"""
md = """ md = """
backup news md export md
Send a Markdown file of your news items. Send a Markdown file with feeds.
"""
text = """
backup news text
Send a Plain Text file of your news items.
""" """
# html = """
# backup news html
# Send an HTML formatted file of your news items.
# """
# md = """
# backup news md
# Send a Markdown file of your news items.
# """
# text = """
# backup news text
# Send a Plain Text file of your news items.
# """
[bookmarks] [bookmarks]
bookmark = """ bookmark = """
@ -121,19 +125,19 @@ help <key>
Print list of commands for selected command type. Print list of commands for selected command type.
""" """
[mastership] # [mastership]
demaster = """ # demaster = """
demaster <nick> # demaster <nick>
Remove master privilege from given <nick>. # Remove master privilege from given <nick>.
""" # """
mastership = """ # mastership = """
mastership <nick> # mastership <nick>
Add master privilege to given <nick>. # Add master privilege to given <nick>.
""" # """
ownership = """ # ownership = """
ownership <nick> # ownership <nick>
Transfer ownership to given <nick>. # Transfer ownership to given <nick>.
""" # """
[message] [message]
interval = """ interval = """
@ -232,21 +236,21 @@ stats = """
stats stats
Show general statistics. Show general statistics.
""" """
analyses = """ # analyses = """
analyses # analyses
Show report and statistics of feeds. # Show report and statistics of feeds.
""" # """
obsolete = """ # obsolete = """
obsolete # obsolete
List feeds that are not available. # List feeds that are not available.
""" # """
unread = """ # unread = """
unread # unread
Print number of unread news items. # Print number of unread news items.
""" # """
[token] # [token]
activate = """ # activate = """
activate <code> # activate <code>
Activate given token to command bot by given <code>. # Activate given token to command bot by given <code>.
""" # """

View file

@ -166,6 +166,11 @@ async def http(url):
result = {'error': True, result = {'error': True,
'message': 'Timeout:' + str(e), 'message': 'Timeout:' + str(e),
'original_url': url} 'original_url': url}
except Exception as e:
logging.error(e)
result = {'error': True,
'message': 'Error:' + str(e),
'original_url': url}
return result return result

View file

@ -629,6 +629,38 @@ async def remove_feed_by_index(db_file, ix):
cur.execute(sql, par) cur.execute(sql, par)
def get_feeds_by_tag_id(db_file, tag_id):
"""
Get feeds of given tag.
Parameters
----------
db_file : str
Path to database file.
tag_id : str
Tag ID.
Returns
-------
result : tuple
List of tags.
"""
with create_connection(db_file) as conn:
cur = conn.cursor()
sql = (
"""
SELECT feeds.*
FROM feeds
INNER JOIN feeds_tags ON feeds.id = feeds_tags.feed_id
INNER JOIN tags ON tags.id = feeds_tags.tag_id
WHERE tags.id = ?;
"""
)
par = (tag_id,)
result = cur.execute(sql, par).fetchall()
return result
def get_tags_by_feed_id(db_file, feed_id): def get_tags_by_feed_id(db_file, feed_id):
""" """
Get tags of given feed. Get tags of given feed.
@ -642,7 +674,7 @@ def get_tags_by_feed_id(db_file, feed_id):
Returns Returns
------- -------
result : list result : tuple
List of tags. List of tags.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -693,7 +725,7 @@ async def set_feed_id_and_tag_id(db_file, feed_id, tag_id):
cur.execute(sql, par) cur.execute(sql, par)
def get_tag_id(db_file, tag): def get_tag_id(db_file, tag_name):
""" """
Get ID of given tag. Check whether tag exist. Get ID of given tag. Check whether tag exist.
@ -701,8 +733,8 @@ def get_tag_id(db_file, tag):
---------- ----------
db_file : str db_file : str
Path to database file. Path to database file.
tag : str tag_name : str
Tag. Tag name.
Returns Returns
------- -------
@ -718,11 +750,41 @@ def get_tag_id(db_file, tag):
WHERE tag = ? WHERE tag = ?
""" """
) )
par = (tag,) par = (tag_name,)
ix = cur.execute(sql, par).fetchone() ix = cur.execute(sql, par).fetchone()
return ix return ix
def get_tag_name(db_file, ix):
"""
Get name of given tag. Check whether tag exist.
Parameters
----------
db_file : str
Path to database file.
ix : str
Tag ID.
Returns
-------
tag_name : str
Tag name.
"""
with create_connection(db_file) as conn:
cur = conn.cursor()
sql = (
"""
SELECT tag
FROM tags
WHERE id = ?
"""
)
par = (ix,)
tag_name = cur.execute(sql, par).fetchone()
return tag_name
def is_tag_id_associated(db_file, tag_id): def is_tag_id_associated(db_file, tag_id):
""" """
Check whether tag_id is associated with any feed. Check whether tag_id is associated with any feed.
@ -869,7 +931,7 @@ async def get_feed_id_and_name(db_file, url):
Returns Returns
------- -------
result : list result : tuple
List of ID and Name of feed. List of ID and Name of feed.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -988,7 +1050,7 @@ async def get_unread_entries(db_file, num):
Returns Returns
------- -------
results : ??? result : tuple
News items. News items.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -1006,8 +1068,8 @@ async def get_unread_entries(db_file, num):
""" """
) )
par = (num,) par = (num,)
results = cur.execute(sql, par).fetchall() result = cur.execute(sql, par).fetchall()
return results return result
def get_feed_id_by_entry_index(db_file, ix): def get_feed_id_by_entry_index(db_file, ix):
@ -1525,7 +1587,7 @@ async def add_entries_and_update_timestamp(db_file, feed_id, new_entries):
---------- ----------
db_file : str db_file : str
Path to database file. Path to database file.
new_entries : list new_entries : tuple
Set of entries as dict. Set of entries as dict.
""" """
async with DBLOCK: async with DBLOCK:
@ -1779,7 +1841,7 @@ async def get_entries_of_feed(db_file, feed_id):
# Returns # Returns
# ------- # -------
# result : list # result : tuple
# Title, URL, Categories, Tags of feeds. # Title, URL, Categories, Tags of feeds.
# """ # """
# with create_connection(db_file) as conn: # with create_connection(db_file) as conn:
@ -1804,7 +1866,7 @@ async def get_feeds_url(db_file):
Returns Returns
------- -------
result : list result : tuple
URLs of active feeds. URLs of active feeds.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -1819,6 +1881,41 @@ async def get_feeds_url(db_file):
return result return result
def get_feeds_by_enabled_state(db_file, enabled_state):
"""
Query table feeds by enabled state.
Parameters
----------
db_file : str
Path to database file.
enabled_state : boolean
False or True.
Returns
-------
result : tuple
List of URLs.
"""
if enabled_state:
enabled_state = 1
else:
enabled_state = 0
with create_connection(db_file) as conn:
cur = conn.cursor()
sql = (
"""
SELECT feeds.*
FROM feeds
INNER JOIN feeds_state ON feeds.id = feeds_state.feed_id
WHERE feeds_state.enabled = ?
"""
)
par = (enabled_state,)
result = cur.execute(sql, par).fetchall()
return result
async def get_active_feeds_url(db_file): async def get_active_feeds_url(db_file):
""" """
Query table feeds for active URLs. Query table feeds for active URLs.
@ -1830,7 +1927,7 @@ async def get_active_feeds_url(db_file):
Returns Returns
------- -------
result : list result : tuple
URLs of active feeds. URLs of active feeds.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -1847,6 +1944,32 @@ async def get_active_feeds_url(db_file):
return result return result
def get_tags(db_file):
"""
Query table tags and list items.
Parameters
----------
db_file : str
Path to database file.
Returns
-------
result : tuple
List of tags.
"""
with create_connection(db_file) as conn:
cur = conn.cursor()
sql = (
"""
SELECT tag, id
FROM tags
"""
)
result = cur.execute(sql).fetchall()
return result
async def get_feeds(db_file): async def get_feeds(db_file):
""" """
Query table feeds and list items. Query table feeds and list items.
@ -1858,14 +1981,14 @@ async def get_feeds(db_file):
Returns Returns
------- -------
results : ??? result : tuple
URLs of feeds. URLs of feeds.
""" """
# TODO # TODO
# 1) Select id from table feeds # 1) Select id from table feeds
# Select name, url (feeds) updated, enabled, feed_id (status) # Select name, url (feeds) updated, enabled, feed_id (status)
# 2) Sort feeds by id. Sort status by feed_id # 2) Sort feeds by id. Sort status by feed_id
# results += cur.execute(sql).fetchall() # result += cur.execute(sql).fetchall()
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
cur = conn.cursor() cur = conn.cursor()
sql = ( sql = (
@ -1874,8 +1997,8 @@ async def get_feeds(db_file):
FROM feeds FROM feeds
""" """
) )
results = cur.execute(sql).fetchall() result = cur.execute(sql).fetchall()
return results return result
async def last_entries(db_file, num): async def last_entries(db_file, num):
@ -1891,7 +2014,7 @@ async def last_entries(db_file, num):
Returns Returns
------- -------
titles_list : str titles_list : tuple
List of recent N entries as message. List of recent N entries as message.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -1916,8 +2039,8 @@ async def last_entries(db_file, num):
""" """
) )
par = (num,) par = (num,)
results = cur.execute(sql, par).fetchall() result = cur.execute(sql, par).fetchall()
return results return result
def search_feeds(db_file, query): def search_feeds(db_file, query):
@ -1933,7 +2056,7 @@ def search_feeds(db_file, query):
Returns Returns
------- -------
titles_list : str result : tuple
Feeds of specified keywords as message. Feeds of specified keywords as message.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -1948,8 +2071,8 @@ def search_feeds(db_file, query):
""" """
) )
par = [f'%{query}%', f'%{query}%'] par = [f'%{query}%', f'%{query}%']
results = cur.execute(sql, par).fetchall() result = cur.execute(sql, par).fetchall()
return results return result
async def search_entries(db_file, query): async def search_entries(db_file, query):
@ -1965,7 +2088,7 @@ async def search_entries(db_file, query):
Returns Returns
------- -------
titles_list : str titles_list : tuple
Entries of specified keywords as message. Entries of specified keywords as message.
""" """
with create_connection(db_file) as conn: with create_connection(db_file) as conn:
@ -1983,8 +2106,8 @@ async def search_entries(db_file, query):
""" """
) )
par = (f'%{query}%', f'%{query}%') par = (f'%{query}%', f'%{query}%')
results = cur.execute(sql, par).fetchall() result = cur.execute(sql, par).fetchall()
return results return result
""" """
@ -2605,31 +2728,31 @@ def get_nations(db_file):
return locales return locales
def get_tags(db_file): # def get_tags(db_file):
""" # """
Get list of title and urls. # Get list of title and urls.
Parameters # Parameters
---------- # ----------
db_file : str # db_file : str
Path to database file. # Path to database file.
Returns # Returns
------- # -------
titles_urls : tuple # titles_urls : tuple
List of titles and urls. # List of titles and urls.
""" # """
with create_connection(db_file) as conn: # with create_connection(db_file) as conn:
cur = conn.cursor() # cur = conn.cursor()
sql = ( # sql = (
""" # """
SELECT tags # SELECT tags
FROM entries # FROM entries
ORDER BY tags ASC # ORDER BY tags ASC
""" # """
) # )
titles_urls = cur.execute(sql).fetchall() # titles_urls = cur.execute(sql).fetchall()
return titles_urls # return titles_urls
def get_titles_tags_urls(db_file): def get_titles_tags_urls(db_file):

View file

@ -1,2 +1,2 @@
__version__ = '0.1.23' __version__ = '0.1.24'
__version_info__ = (0, 1, 23) __version_info__ = (0, 1, 24)

File diff suppressed because it is too large Load diff

2091
slixfeed/xmpp/command.py Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -648,7 +648,7 @@ async def message(self, message):
result['name'], result['name'],
result['index'])) result['index']))
elif result['error']: elif result['error']:
response = ('> {}\nFailed to load URL. Reason: {}' response = ('> {}\nFailed to find subscriptions. Reason: {}'
.format(url, result['code'])) .format(url, result['code']))
else: else:
response = ('> {}\nNews source "{}" has been ' response = ('> {}\nNews source "{}" has been '