]> git.mxchange.org Git - fba.git/blob - fetch_instances.py
Continued:
[fba.git] / fetch_instances.py
1 import sqlite3
2 import sys
3 import json
4 import time
5 import fba
6
7 def fetch_instances(domain: str):
8     print("DEBUG: Fetching instances for domain:", domain)
9     peerlist = fba.get_peers(domain)
10
11     if (peerlist is None):
12         print("ERROR: Cannot fetch peers:", domain)
13         return
14
15     for instance in peerlist:
16         instance = instance.lower()
17         if instance.find("@") > 0:
18             print("WARNING: Bad instance name,domain:", instance, domain)
19             continue
20
21         blacklisted = False
22         for domain in fba.blacklist:
23             if domain in instance:
24                 blacklisted = True
25
26         if blacklisted:
27             # NOISY-DEBUG: print("DEBUG: domain is blacklisted:", domain)
28             continue
29
30         # NOISY-DEBUG: print("DEBUG: Handling instance:", instance)
31         try:
32             fba.c.execute(
33                 "SELECT domain FROM instances WHERE domain = ? LIMIT 1", (instance,)
34             )
35
36             if fba.c.fetchone() == None:
37                 # NOISY-DEBUG: print("DEBUG: Adding new instance:", instance)
38                 fba.add_instance(instance)
39
40             fba.conn.commit()
41
42         except Exception as e:
43             print("ERROR:", e, instance)
44             continue
45
46 instance = sys.argv[1]
47
48 # Initial fetch
49 fetch_instances(instance)
50
51 # Loop through some instances
52 fba.c.execute(
53     "SELECT domain FROM instances WHERE software IS NOT NULL AND (last_nodeinfo IS NULL OR last_nodeinfo < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]]
54 )
55
56 for instance in fba.c.fetchall():
57     blacklisted = False
58     for domain in fba.blacklist:
59         if domain in instance[0]:
60             blacklisted = True
61
62     if blacklisted:
63         # NOISY-DEBUG: print("DEBUG: domain is blacklisted:", instance)
64         continue
65
66     print("DEBUG: Fetching instances for instance:", instance[0])
67     fetch_instances(instance[0])
68
69 fba.conn.close()