]> git.mxchange.org Git - fba.git/blob - fetch_fba_rss.py
614b10e885510ddcd1ce078578fdbbd7ec2c2050
[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 atoma
22 import sys
23 from fba import *
24
25 feed = sys.argv[1]
26
27 domains = list()
28 try:
29     print(f"INFO: Fetch FBA-specific RSS feed='{feed}' ...")
30     response = reqto.get(feed, headers=fba.headers, timeout=(config.get("connection_timeout"), config.get("read_timeout")))
31
32     # DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code='{response.status_code}',response.text()={len(response.text)}")
33     if response.ok and response.status_code < 300 and len(response.text) > 0:
34         # DEBUG: print(f"DEBUG: Parsing RSS feed ...")
35         rss = atoma.parse_rss_bytes(response.content)
36
37         # DEBUG: print(f"DEBUG: rss[]={type(rss)}")
38         for item in rss.items:
39             # DEBUG: print(f"DEBUG: item={item}")
40             domain = item.link.split("=")[1]
41
42             if fba.is_blacklisted(domain):
43                 # DEBUG: print(f"DEBUG: domain='{domain}' is blacklisted - SKIPPED!")
44                 continue
45             elif domain in domains:
46                 # DEBUG: print(f"DEBUG: domain='{domain}' is already added - SKIPPED!")
47                 continue
48             elif fba.is_instance_registered(domain):
49                 # DEBUG: print(f"DEBUG: domain='{domain}' is already registered - SKIPPED!")
50                 continue
51
52             # DEBUG: print(f"DEBUG: domain='{domain}'")
53             domains.append(domain)
54
55 except BaseException as e:
56     print(f"ERROR: Cannot fetch feed='{feed}',exception[{type(e)}]:'{str(e)}'")
57
58 # DEBUG: print(f"DEBUG: domains()={len(domains)}")
59 if len(domains) > 0:
60     boot.acquire_lock()
61
62     print(f"INFO: Adding {len(domains)} new instances ...")
63     for domain in domains:
64         print(f"INFO: Fetching instances from domain='{domain}' ...")
65         fba.fetch_instances(domain, None, None, sys.argv[0])
66
67 boot.shutdown()