(Hopefully) Fix fetching of new subscriptions.

This commit is contained in:
Schimon Jehudah 2024-03-13 15:44:20 +00:00
parent 1b2167f207
commit 3c89b84908
5 changed files with 18 additions and 15 deletions

View file

@ -770,11 +770,11 @@ async def add_feed(self, jid_bare, db_file, url):
while True:
exist = sqlite.get_feed_id_and_name(db_file, url)
if not exist:
status_code = None
result = await fetch.http(url)
message = result['message']
status_code = result['status_code']
if not result['error']:
document = result['content']
status_code = result['status_code']
feed = parse(document)
# if is_feed(url, feed):
if is_feed(feed):
@ -880,7 +880,7 @@ async def add_feed(self, jid_bare, db_file, url):
'name' : None,
'code' : status_code,
'error' : True,
'message': result['message'],
'message': message,
'exist' : False}
break
elif isinstance(result, list):
@ -896,18 +896,19 @@ async def add_feed(self, jid_bare, db_file, url):
'name' : None,
'code' : status_code,
'error' : True,
'message': result['message'],
'message': message,
'exist' : False}
break
else:
ix = exist[0]
name = exist[1]
message = 'URL already exist.'
result_final = {'link' : url,
'index' : ix,
'name' : name,
'code' : None,
'error' : False,
'message': result['message'],
'message': message,
'exist' : True}
break
return result_final

View file

@ -123,7 +123,7 @@ async def http(url):
or 'Slixfeed/0.1')
headers = {'User-Agent': user_agent}
proxy = (config.get_values('settings.toml', 'network')['http_proxy']
or '')
or None)
timeout = ClientTimeout(total=10)
async with ClientSession(headers=headers) as session:
# async with ClientSession(trust_env=True) as session:
@ -159,18 +159,18 @@ async def http(url):
'response_url': response.url}
except ClientError as e:
result = {'error': True,
'message': 'Error:' + str(e),
'message': 'Error:' + str(e) if e else 'ClientError',
'original_url': url,
'status_code': None}
except TimeoutError as e:
result = {'error': True,
'message': 'Timeout:' + str(e),
'message': 'Timeout:' + str(e) if e else 'TimeoutError',
'original_url': url,
'status_code': None}
except Exception as e:
logging.error(e)
result = {'error': True,
'message': 'Error:' + str(e),
'message': 'Error:' + str(e) if e else 'Error',
'original_url': url,
'status_code': None}
return result

View file

@ -1,2 +1,2 @@
__version__ = '0.1.42'
__version_info__ = (0, 1, 42)
__version__ = '0.1.43'
__version_info__ = (0, 1, 43)

View file

@ -1250,8 +1250,9 @@ class Slixfeed(slixmpp.ClientXMPP):
session['payload'] = form
# session['prev'] = self._handle_subscription_add
elif result['error']:
response = ('Failed to load URL <{}> Reason: {}'
.format(url, result['code']))
response = ('Failed to load URL <{}> Reason: {} '
'(status code: {})'
.format(url, result['message'], result['code']))
session['allow_prev'] = True
session['next'] = None
session['notes'] = [['error', response]]

View file

@ -1210,8 +1210,9 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
session['payload'] = form
# session['prev'] = self._handle_subscription_add
elif result['error']:
response = ('Failed to load URL <{}> Reason: {}'
.format(url, result['code']))
response = ('Failed to load URL <{}> Reason: {} '
'(status code: {})'
.format(url, result['message'], result['code']))
session['allow_prev'] = True
session['next'] = None
session['notes'] = [['error', response]]