Skip to content
Snippets Groups Projects
Commit c92e82b2 authored by psy's avatar psy
Browse files

do http calls with requests

parent 55d72d9c
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import argparse
import time
import traceback
import feedparser
import requests
from threading import Thread, Condition
from matrix_client.errors import MatrixRequestError
from matrix_client.client import MatrixClient
......@@ -149,10 +150,23 @@ Invite me to any room on {homeserver} and use the custom state event <code>de.ev
if url in feeds]
def _fetch_feed(self, url):
# FIXME: one site with slow response times can block all feeds
print('Fetching updates from {}'.format(url))
try:
feed = feedparser.parse(url)
response = requests.get(url, timeout=10)
except requests.RequestException as e:
print(f'error fetching feed {url}: {e}')
return
if response.status_code != 200:
print(f'error fetching feed {url}, got status {response.status_code}.')
return
feed = feedparser.parse(response.text)
if feed.bozo:
print(f'error parsing feed {url}: {feed.bozo_exception}.')
return
feed_title = feed.feed.title
to_be_sent = []
any_knowns = False
......@@ -184,9 +198,6 @@ Invite me to any room on {homeserver} and use the custom state event <code>de.ev
print(raw)
for room in self.get_rooms_for_feed(url):
room.send_html(html, raw, 'm.notice')
except Exception:
print('Failed to parse feed {}: {}'
.format(url, traceback.format_exc()))
def run(self):
self._fetch_thread.start()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment