]> git.mxchange.org Git - fba.git/blob - fetch_instances.py
WIP:
[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("FATAL: CANNOT FETCH PEERS:", domain)
12         return
13
14     for instance in peerlist:
15         instance = instance.lower()
16
17         blacklisted = False
18         for domain in fba.blacklist:
19             if domain in instance:
20                 blacklisted = True
21
22         if blacklisted:
23             # NOISY-DEBUG: print("DEBUG: domain is blacklisted:", domain)
24             continue
25
26         # NOISY-DEBUG: print("DEBUG: Handling instance:", instance)
27         try:
28             fba.c.execute(
29                 "SELECT domain FROM instances WHERE domain = ? LIMIT 1", (instance,)
30             )
31
32             if fba.c.fetchone() == None:
33                 # NOISY-DEBUG: print("DEBUG: Adding new instance:", instance)
34                 fba.add_instance(instance)
35
36             fba.conn.commit()
37
38         except Exception as e:
39             print("ERROR:", e, instance)
40             continue
41
42 instance = sys.argv[1]
43
44 # Initial fetch
45 fetch_instances(instance)
46
47 # Loop through some instances
48 fba.c.execute(
49     "SELECT domain FROM instances WHERE software IS NOT NULL ORDER BY rowid DESC"
50 )
51
52 for instance in fba.c.fetchall():
53     blacklisted = False
54     for domain in fba.blacklist:
55         if domain in instance[0]:
56             blacklisted = True
57
58     if blacklisted:
59         # NOISY-DEBUG: print("DEBUG: domain is blacklisted:", instance)
60         continue
61
62     print("DEBUG: Fetching instances for instance:", instance[0])
63     fetch_instances(instance[0])
64
65 fba.conn.close()