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