Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-rssbot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
infra
matrix-rssbot
Commits
c92e82b2
Commit
c92e82b2
authored
Oct 16, 2023
by
psy
Browse files
Options
Downloads
Patches
Plain Diff
do http calls with requests
parent
55d72d9c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rssbot.py
+44
-33
44 additions, 33 deletions
rssbot.py
with
44 additions
and
33 deletions
rssbot.py
+
44
−
33
View file @
c92e82b2
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment