1 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
2 # Copyright (C) 2023 Free Software Foundation
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 from fba import database
23 from fba.helpers import config
24 from fba.helpers import domain as domain_helper
26 logging.basicConfig(level=logging.INFO)
27 logger = logging.getLogger(__name__)
29 def is_recent(api_domain: str) -> bool:
30 logger.debug("api_domain='%s' - CALLED!", api_domain)
31 domain_helper.raise_on(api_domain)
34 database.cursor.execute("SELECT last_accessed FROM apis WHERE hostname = ? LIMIT 1", [api_domain])
36 row = database.cursor.fetchone()
37 logger.debug("row[]='%s'", type(row))
39 logger.debug("api_domain='%s',row[last_accessed]=%d", api_domain, row["last_accessed"])
40 is_recent = (time.time() - row["last_accessed"]) <= config.get("api_last_access")
42 logger.debug("is_recent='%s' - EXIT!", is_recent)
45 def update (api_domain: str):
46 logger.debug("api_domain='%s' - CALLED!", api_domain)
47 domain_helper.raise_on(api_domain)
49 database.cursor.execute("SELECT * FROM apis WHERE hostname = ? LIMIT 1", [api_domain])
51 row = database.cursor.fetchone()
52 logger.debug("row[]='%s'", type(row))
55 database.cursor.execute("INSERT INTO apis (hostname, last_accessed) VALUES (?, ?)", [
60 # Update last_accessed
61 database.cursor.execute("UPDATE apis SET last_accessed = ? WHERE hostname = ? LIMIT 1", [