2 # -*- coding: utf-8 -*-
4 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
5 # Copyright (C) 2023 Free Software Foundation
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.
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.
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/>.
31 print(f"INFO: Fetch FBA-specific RSS feed='{feed}' ...")
32 res = reqto.get(feed, headers=fba.headers, timeout=(fba.config["connection_timeout"], fba.config["read_timeout"]))
34 # DEBUG: print(f"DEBUG: res.ok={res.ok},res.status_code='{res.status_code}',res.text()={len(res.text)}")
35 if res.ok and res.status_code < 300 and len(res.text) > 0:
36 # DEBUG: print(f"DEBUG: Parsing RSS feed ...")
37 rss = rss_parser.Parser.parse(res.text)
38 for item in rss.channel.items:
39 # DEBUG: print(f"DEBUG: item.link={item.link}")
40 domain = item.link.split("=")[1]
42 if fba.is_blacklisted(domain):
43 # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted - SKIPPED!")
45 elif domain in domains:
46 # DEBUG: print(f"DEBUG: domain='{domain}' is already added - SKIPPED!")
48 elif fba.is_instance_registered(domain):
49 # DEBUG: print(f"DEBUG: domain='{domain}' is already registered - SKIPPED!")
52 # DEBUG: print(f"DEBUG: domain='{domain}'")
53 domains.append(domain)
55 except BaseException as e:
56 print(f"ERROR: Cannot fetch feed='{feed}',exception[{type(e)}]:'{str(e)}'")
59 # DEBUG: print(f"DEBUG: domains()={len(domains)}")
61 print(f"INFO: Adding {len(domains)} new instances ...")
62 for domain in domains:
63 print(f"INFO: Fetching instances from domain='{domain}' ...")
64 fba.fetch_instances(domain, None, None, sys.argv[0])