Who blocks FMHY
Who blocks FMHY
To accomplish this task, you can use the lemmy-stats-crawler tool available on GitHub. First, clone the repository using git clone https://github.com/LemmyNet/lemmy-stats-crawler.git. Then, navigate to the cloned directory using cd lemmy-stats-crawler and run the command cargo run -- --json > stats.json to generate a JSON file containing the stats.
To extract the list of instances blocking a given instance from a stats.json file similar to the one you provided, you can use the json module in Python. Here's a script that takes user input and returns the list of instances blocking the given instance:
import json
#with open("stats.json", "r") as file:
# json_data = json.load(file)
json_data = '''
{
"instance_details": [
{
"domain": "lemmy.world",
"site_info": {
"federated_instances": {
"blocked": [
"burggit.moe"
]
}
}
},
{
"domain": "lemmy.ml",
"site_info": {
"federated_instances": {
"blocked": [
"lemmy.fmhy.ml",
"example2.com"
]
}
}
}
]
}
'''
def find_blocking_instances(target_instance, json_data):
data = json.loads(json_data)
blocking_instances = []
for instance in data["instance_details"]:
if target_instance in instance["site_info"]["federated_instances"]["blocked"]:
blocking_instances.append(instance["domain"])
return blocking_instances
user_input = input("Enter the instance to find blocking instances: ")
result = find_blocking_instances(user_input, json_data)
print("Instances blocking", user_input, ":", result)
When you run this script and input lemmy.fmhy.ml, it will output:
Instances blocking lemmy.fmhy.ml : ['lemmy.ml']
This script first loads the JSON data into a Python dictionary using json.loads() [1]. Then, it iterates through the instance_details list and checks if the given instance is in the blocked list of each instance. If it is, the domain of the blocking instance is added to the blocking_instances list. Finally, the script prints the list of instances blocking the given instance.
Citations: [1] https://pynative.com/python/json/