]> git.mxchange.org Git - fba.git/blob - fetch_instances.py
Continued:
[fba.git] / fetch_instances.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 sqlite3
21 import sys
22 import json
23 import time
24 import validators
25 import fba
26
27 instance = sys.argv[1]
28
29 # Initial fetch
30 fba.fetch_instances(instance, None, None, sys.argv[0])
31
32 # Loop through some instances
33 fba.cursor.execute(
34     "SELECT domain, origin, software, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]]
35 )
36
37 rows = fba.cursor.fetchall()
38 print(f"INFO: Checking {len(rows)} entries ...")
39 for row in rows:
40     # DEBUG: print("DEBUG: domain:", row[0])
41     if fba.is_blacklisted(row[0]):
42         print("WARNING: domain is blacklisted:", row[0])
43         continue
44
45     print(f"INFO: Fetching instances for instance '{row[0]}' ('{row[2]}') of origin='{row[1]}',nodeinfo_url='{row[3]}'")
46     fba.fetch_instances(row[0], row[1], row[2], sys.argv[0], row[3])
47
48 fba.connection.close()