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/>.
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"]))
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]
40 if fba.is_blacklisted(domain):
41 # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted - SKIPPED!")
43 elif domain in domains:
44 # DEBUG: print(f"DEBUG: domain='{domain}' is already added - SKIPPED!")
46 elif fba.is_instance_registered(domain):
47 # DEBUG: print(f"DEBUG: domain='{domain}' is already registered - SKIPPED!")
50 # DEBUG: print(f"DEBUG: domain='{domain}'")
51 domains.append(domain)
53 except BaseException as e:
54 print(f"ERROR: Cannot fetch feed='{feed}',exception[{type(e)}]:'{str(e)}'")
57 # DEBUG: print(f"DEBUG: domains()={len(domains)}")
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])
64 fba.connection.close()