]> git.mxchange.org Git - fba.git/blob - fetch_fba_rss.py
Continued:
[fba.git] / fetch_fba_rss.py
1 #!/usr/bin/python3
2 # -*- coding: utf-8 -*-
3
4 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
5 # Copyright (C) 2023 Free Software Foundation
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published
9 # by the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16 #
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
20 import reqto
21 import rss_parser
22 import sys
23 import fba
24
25 feed = sys.argv[1]
26
27 domains = list()
28 try:
29     print(f"INFO: Fetch FBA-specific RSS feed='{feed}' ...")
30     res = reqto.get(feed, headers=fba.headers, timeout=(fba.config["connection_timeout"], fba.config["read_timeout"]))
31
32     # DEBUG: print(f"DEBUG: res.ok={res.ok},res.status_code='{res.status_code}',res.text()={len(res.text)}")
33     if res.ok and res.status_code < 300 and len(res.text) > 0:
34         # DEBUG: print(f"DEBUG: Parsing RSS feed ...")
35         rss = rss_parser.Parser.parse(res.text)
36         for item in rss.channel.items:
37             # DEBUG: print(f"DEBUG: item.link={item.link}")
38             domain = item.link.split("=")[1]
39
40             if fba.is_blacklisted(domain):
41                 # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted - SKIPPED!")
42                 continue
43             elif domain in domains:
44                 # DEBUG: print(f"DEBUG: domain='{domain}' is already added - SKIPPED!")
45                 continue
46             elif fba.is_instance_registered(domain):
47                 # DEBUG: print(f"DEBUG: domain='{domain}' is already registered - SKIPPED!")
48                 continue
49
50             # DEBUG: print(f"DEBUG: domain='{domain}'")
51             domains.append(domain)
52
53 except BaseException as e:
54     print(f"ERROR: Cannot fetch feed='{feed}',exception[{type(e)}]:'{str(e)}'")
55
56 # Show domains
57 # DEBUG: print(f"DEBUG: domains()={len(domains)}")
58 if len(domains) > 0:
59     print(f"INFO: Adding {len(domains)} new instances ...")
60     for domain in domains:
61         print(f"INFO: Fetching instances from domain='{domain}' ...")
62         fba.fetch_instances(domain, None, None, sys.argv[0])
63
64 fba.connection.close()