foundkey-survey/foundkey-survey.py

45 lines
1.4 KiB
Python
Raw Normal View History

2023-05-01 11:09:27 +00:00
#!/bin/env python3
import csv
import requests
# check which hostnames were fetched already
f = open('survey.csv')
reader = csv.reader(f, delimiter=',', quotechar='"')
known_instances = set()
for row in reader:
known_instances.add(row[0])
# open survey.csv for appending now
f = open('survey.csv', 'a', newline='')
writer = csv.writer(f, delimiter=',', quotechar='"')
# reader for instances to fetch
f = open('instances.csv', mode='r+')
reader = csv.reader(f, delimiter=',', quotechar='"')
for row in reader:
instance = row[0]
if instance not in known_instances:
print("checking", instance)
# fetch nodeinfo data
try:
r = requests.get(
'https://{}/nodeinfo/2.1'.format(instance),
headers={'user-agent': 'foundkey instance survey'},
timeout=30
)
except:
print("dead")
continue
if not r.status_code == 200:
print("skipping, status {}".format(r.status_code))
continue
body = r.json()['metadata']
# select some data from nodeinfo and write it to resuling CSV file
writer.writerow([instance, body['enableDiscordIntegration'], body['enableGithubIntegration'], body['enableTwitterIntegration']])
print("done")
# make sure duplicates are not fetched
known_instances.add(instance)