Fix updates retrieval

This commit is contained in:
Schimon Jehudah 2024-01-04 13:58:06 +00:00
parent b77ef5346f
commit 6b07640666
6 changed files with 81 additions and 39 deletions

View file

@ -21,7 +21,7 @@ async def add_feed(db_file, url):
while True: while True:
exist = await sqlite.is_feed_exist(db_file, url) exist = await sqlite.is_feed_exist(db_file, url)
if not exist: if not exist:
result = await fetch.download_feed([url]) result = await fetch.download_feed(url)
document = result[0] document = result[0]
status = result[1] status = result[1]
if document: if document:
@ -82,7 +82,7 @@ async def add_feed(db_file, url):
async def view_feed(url): async def view_feed(url):
while True: while True:
result = await fetch.download_feed([url]) result = await fetch.download_feed(url)
document = result[0] document = result[0]
status = result[1] status = result[1]
if document: if document:
@ -151,7 +151,7 @@ async def view_feed(url):
async def view_entry(url, num): async def view_entry(url, num):
while True: while True:
result = await fetch.download_feed([url]) result = await fetch.download_feed(url)
document = result[0] document = result[0]
status = result[1] status = result[1]
if document: if document:
@ -320,6 +320,7 @@ async def organize_items(db_file, urls):
db_file, source, eid=eid, db_file, source, eid=eid,
title=title, link=link, date=date) title=title, link=link, date=date)
if not exist: if not exist:
print(url)
# new_entry = new_entry + 1 # new_entry = new_entry + 1
# TODO Enhance summary # TODO Enhance summary
if entry.has_key("summary"): if entry.has_key("summary"):
@ -384,7 +385,7 @@ async def remove_nonexistent_entries(db_file, feed, source):
source : str source : str
Feed URL. URL of associated feed. Feed URL. URL of associated feed.
""" """
items = sqlite.get_entries_of_source(db_file, feed, source) items = await sqlite.get_entries_of_source(db_file, feed, source)
entries = feed.entries entries = feed.entries
# breakpoint() # breakpoint()
for item in items: for item in items:

View file

@ -66,10 +66,11 @@ async def download_feed(url):
msg: list or str msg: list or str
Document or error message. Document or error message.
""" """
user_agent = (config.get_value( user_agent = (
"settings", "Network", "user-agent")) or 'Slixfeed/0.1' config.get_value(
"settings", "Network", "user-agent")
) or 'Slixfeed/0.1'
headers = {'User-Agent': user_agent} headers = {'User-Agent': user_agent}
url = url[0]
proxy = (config.get_value( proxy = (config.get_value(
"settings", "Network", "http_proxy")) or '' "settings", "Network", "http_proxy")) or ''
timeout = ClientTimeout(total=10) timeout = ClientTimeout(total=10)

View file

@ -829,9 +829,9 @@ async def add_entry(cur, entry):
try: try:
cur.execute(sql, entry) cur.execute(sql, entry)
except: except:
None # None
# print("Unknown error for sqlite.add_entry") print("Unknown error for sqlite.add_entry")
# print(entry) print(entry)
# #
# print(current_time(), "COROUTINE OBJECT NOW") # print(current_time(), "COROUTINE OBJECT NOW")
# for i in entry: # for i in entry:

View file

@ -288,7 +288,7 @@ async def send_status(self, jid):
""" """
logging.debug( logging.debug(
"Sending a status message to JID {}".format(jid)) "Sending a status message to JID {}".format(jid))
status_text = "🤖 Slixfeed RSS News Bot" status_text = "📜 Slixfeed RSS News Bot"
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
enabled = ( enabled = (
await get_settings_value( await get_settings_value(

View file

@ -2,7 +2,16 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
TODO Port functions insert_feed, remove_feed, get_entry_unread
TODO
1) Port functions insert_feed, remove_feed, get_entry_unread.
2) Merge with action.py
3) Call sqlite function from function statistics.
Returning a list of values doesn't' seem to be a good practice.
""" """
import slixfeed.xmpp.bookmark as bookmark import slixfeed.xmpp.bookmark as bookmark

View file

@ -259,9 +259,12 @@ async def message(self, message):
val = message_text[7:] val = message_text[7:]
if val: if val:
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
keywords = await sqlite.get_filters_value(db_file, key) keywords = await sqlite.get_filters_value(
val = await add_to_list(val, keywords) db_file, key)
await sqlite.set_filters_value(db_file, [key, val]) val = await add_to_list(
val, keywords)
await sqlite.set_filters_value(
db_file, [key, val])
response = ( response = (
"Approved keywords\n" "Approved keywords\n"
"```\n{}\n```" "```\n{}\n```"
@ -274,9 +277,12 @@ async def message(self, message):
val = message_text[7:] val = message_text[7:]
if val: if val:
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
keywords = await sqlite.get_filters_value(db_file, key) keywords = await sqlite.get_filters_value(
val = await remove_from_list(val, keywords) db_file, key)
await sqlite.set_filters_value(db_file, [key, val]) val = await remove_from_list(
val, keywords)
await sqlite.set_filters_value(
db_file, [key, val])
response = ( response = (
"Approved keywords\n" "Approved keywords\n"
"```\n{}\n```" "```\n{}\n```"
@ -293,7 +299,8 @@ async def message(self, message):
response = "Value may not be greater than 500." response = "Value may not be greater than 500."
else: else:
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
await sqlite.set_settings_value(db_file, [key, val]) await sqlite.set_settings_value(
db_file, [key, val])
response = ( response = (
"Maximum archived items has been set to {}." "Maximum archived items has been set to {}."
).format(val) ).format(val)
@ -316,7 +323,8 @@ async def message(self, message):
) )
send_reply_message(self, message, response) send_reply_message(self, message, response)
case "bookmarks": case "bookmarks":
if jid == get_value("accounts", "XMPP", "operator"): if jid == get_value(
"accounts", "XMPP", "operator"):
response = await compose.list_bookmarks(self) response = await compose.list_bookmarks(self)
else: else:
response = ( response = (
@ -329,9 +337,12 @@ async def message(self, message):
val = message_text[6:] val = message_text[6:]
if val: if val:
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
keywords = await sqlite.get_filters_value(db_file, key) keywords = await sqlite.get_filters_value(
val = await add_to_list(val, keywords) db_file, key)
await sqlite.set_filters_value(db_file, [key, val]) val = await add_to_list(
val, keywords)
await sqlite.set_filters_value(
db_file, [key, val])
response = ( response = (
"Rejected keywords\n" "Rejected keywords\n"
"```\n{}\n```" "```\n{}\n```"
@ -344,9 +355,12 @@ async def message(self, message):
val = message_text[6:] val = message_text[6:]
if val: if val:
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
keywords = await sqlite.get_filters_value(db_file, key) keywords = await sqlite.get_filters_value(
val = await remove_from_list(val, keywords) db_file, key)
await sqlite.set_filters_value(db_file, [key, val]) val = await remove_from_list(
val, keywords)
await sqlite.set_filters_value(
db_file, [key, val])
response = ( response = (
"Rejected keywords\n" "Rejected keywords\n"
"```\n{}\n```" "```\n{}\n```"
@ -489,8 +503,9 @@ async def message(self, message):
try: try:
val = int(val) val = int(val)
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
await sqlite.set_settings_value(db_file, [key, val]) await sqlite.set_settings_value(
if val == 0: db_file, [key, val])
if val == 0: # if not val:
response = ( response = (
"Summary length limit is disabled." "Summary length limit is disabled."
) )
@ -530,7 +545,8 @@ async def message(self, message):
send_reply_message(self, message, response) send_reply_message(self, message, response)
case "new": case "new":
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
await sqlite.set_settings_value(db_file, ["old", 0]) await sqlite.set_settings_value(
db_file, ["old", 0])
response = ( response = (
"Only new items of newly added feeds will be sent." "Only new items of newly added feeds will be sent."
) )
@ -538,8 +554,10 @@ async def message(self, message):
# TODO Will you add support for number of messages? # TODO Will you add support for number of messages?
case "next": case "next":
# num = message_text[5:] # num = message_text[5:]
await task.clean_tasks_xmpp(jid, ["interval", "status"]) await task.clean_tasks_xmpp(
await task.start_tasks_xmpp(self, jid, ["interval", "status"]) jid, ["interval", "status"])
await task.start_tasks_xmpp(
self, jid, ["interval", "status"])
# await refresh_task( # await refresh_task(
# self, # self,
# jid, # jid,
@ -557,7 +575,8 @@ async def message(self, message):
# await refresh_task(jid, key, val) # await refresh_task(jid, key, val)
case "old": case "old":
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
await sqlite.set_settings_value(db_file, ["old", 1]) await sqlite.set_settings_value(
db_file, ["old", 1])
response = ( response = (
"All items of newly added feeds will be sent." "All items of newly added feeds will be sent."
) )
@ -572,7 +591,8 @@ async def message(self, message):
# "Every update will contain {} news items." # "Every update will contain {} news items."
# ).format(response) # ).format(response)
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
await sqlite.set_settings_value(db_file, [key, val]) await sqlite.set_settings_value(
db_file, [key, val])
response = ( response = (
"Next update will contain {} news items." "Next update will contain {} news items."
).format(val) ).format(val)
@ -619,7 +639,8 @@ async def message(self, message):
"URL must not contain white space." "URL must not contain white space."
) )
send_reply_message(self, message, response) send_reply_message(self, message, response)
await task.start_tasks_xmpp(self, jid, ["status"]) await task.start_tasks_xmpp(
self, jid, ["status"])
case _ if message_lowercase.startswith("recent"): case _ if message_lowercase.startswith("recent"):
num = message_text[7:] num = message_text[7:]
if num: if num:
@ -682,14 +703,17 @@ async def message(self, message):
await sqlite.mark_all_as_read(db_file) await sqlite.mark_all_as_read(db_file)
response = "All entries have been marked as read." response = "All entries have been marked as read."
send_reply_message(self, message, response) send_reply_message(self, message, response)
await task.start_tasks_xmpp(self, jid, ["status"]) await task.start_tasks_xmpp(
self, jid, ["status"])
case _ if message_lowercase.startswith("search"): case _ if message_lowercase.startswith("search"):
query = message_text[7:] query = message_text[7:]
if query: if query:
if len(query) > 1: if len(query) > 1:
db_file = get_pathname_to_database(jid) db_file = get_pathname_to_database(jid)
results = await sqlite.search_entries(db_file, query) results = await sqlite.search_entries(
response = compose.list_search_results(query, results) db_file, query)
response = compose.list_search_results(
query, results)
else: else:
response = ( response = (
"Enter at least 2 characters to search" "Enter at least 2 characters to search"
@ -777,7 +801,8 @@ async def message(self, message):
case "support": case "support":
# TODO Send an invitation. # TODO Send an invitation.
response = ( response = (
"Join xmpp:slixfeed@chat.woodpeckersnest.space?join") "Join xmpp:slixfeed@chat.woodpeckersnest.space?join"
)
send_reply_message(self, message, response) send_reply_message(self, message, response)
case _ if message_lowercase.startswith("xmpp:"): case _ if message_lowercase.startswith("xmpp:"):
muc_jid = uri.check_xmpp_uri(message_text) muc_jid = uri.check_xmpp_uri(message_text)
@ -828,6 +853,7 @@ def send_reply_message(self, message, response):
message.reply(response).send() message.reply(response).send()
# TODO Solve this function
def send_oob_reply_message(message, url, response): def send_oob_reply_message(message, url, response):
reply = message.reply(response) reply = message.reply(response)
reply['oob']['url'] = url reply['oob']['url'] = url
@ -839,7 +865,12 @@ async def send_oob_message(self, jid, url):
html = ( html = (
f'<body xmlns="http://www.w3.org/1999/xhtml">' f'<body xmlns="http://www.w3.org/1999/xhtml">'
f'<a href="{url}">{url}</a></body>') f'<a href="{url}">{url}</a></body>')
message = self.make_message(mto=jid, mbody=url, mhtml=html, mtype=chat_type) message = self.make_message(
mto=jid,
mbody=url,
mhtml=html,
mtype=chat_type
)
message['oob']['url'] = url message['oob']['url'] = url
message.send() message.send()