]> 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 from fba import *
26
27 boot.acquire_lock()
28
29 instance = sys.argv[1]
30
31 # Initial fetch
32 fba.fetch_instances(instance, None, None, sys.argv[0])
33
34 # Loop through some instances
35 fba.cursor.execute(
36     "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() - config.get("recheck_instance")]
37 )
38
39 rows = fba.cursor.fetchall()
40 print(f"INFO: Checking {len(rows)} entries ...")
41 for row in rows:
42     # DEBUG: print("DEBUG: domain:", row[0])
43     if fba.is_blacklisted(row[0]):
44         print("WARNING: domain is blacklisted:", row[0])
45         continue
46
47     print(f"INFO: Fetching instances for instance '{row[0]}' ('{row[2]}') of origin='{row[1]}',nodeinfo_url='{row[3]}'")
48     fba.fetch_instances(row[0], row[1], row[2], sys.argv[0], row[3])
49
50 boot.shutdown()