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

View file

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

View file

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

View file

@ -1250,8 +1250,9 @@ 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 URL <{}> Reason: {} '
.format(url, result['code'])) '(status code: {})'
.format(url, result['message'], result['code']))
session['allow_prev'] = True session['allow_prev'] = True
session['next'] = None session['next'] = None
session['notes'] = [['error', response]] session['notes'] = [['error', response]]

View file

@ -1210,8 +1210,9 @@ 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 URL <{}> Reason: {} '
.format(url, result['code'])) '(status code: {})'
.format(url, result['message'], result['code']))
session['allow_prev'] = True session['allow_prev'] = True
session['next'] = None session['next'] = None
session['notes'] = [['error', response]] session['notes'] = [['error', response]]