On the sidebar of the main page of the lemmy.world website.
InternetPirate
It's currently at 6k monthly active users, which is significant. However, it's important to note that there are already 16k abandoned accounts.
To accomplish this task, you can use the lemmy-stats-crawler tool available on GitHub.
❯ git clone https://github.com/LemmyNet/lemmy-stats-crawler
❯ cd lemmy-stats-crawler
❯ cargo run -- --json > stats.json
❯ python3 instance_blocking_checker.py
Enter the instance to find blocking instances: lemmy.fmhy.ml
Instances blocking lemmy.fmhy.ml : ['feddit.de', 'civilloquy.com', 'thesimplecorner.org']
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:
instance_blocking_checker.py
import json
with open("stats.json", "r") as file:
data = json.load(file)
def find_blocking_instances(target_instance, data):
blocking_instances = []
for instance in data["instance_details"]:
federated_instances = instance["site_info"]["federated_instances"]
if federated_instances is not None and target_instance in (federated_instances.get("blocked") or []):
blocking_instances.append(instance["domain"])
return blocking_instances
user_input = input("Enter the instance to find blocking instances: ")
result = find_blocking_instances(user_input, 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:
This one is also wrong:
To extract the list of instances blocking a given instance from the provided JSON structure, you can use the json
module in Python. Here's a script that does that:
import json
# Load the JSON data
json_data = '''
{
"instance_details": [
{
"domain": "lemmy.world",
"site_info": {
"federated_instances": {
"blocked": [
"burggit.moe"
]
}
}
},
{
"domain": "lemmy.fmhy.ml",
"site_info": {
"federated_instances": {
"blocked": [
"example1.com",
"example2.com"
]
}
}
}
]
}
'''
# Parse the JSON data
data = json.loads(json_data)
# Function to get blocked instances for a given domain
def get_blocked_instances(domain):
for instance in data["instance_details"]:
if instance["domain"] == domain:
return instance["site_info"]["federated_instances"]["blocked"]
return None
# User input
instance_to_check = "lemmy.fmhy.ml"
# Get the list of blocked instances
blocked_instances = get_blocked_instances(instance_to_check)
# Print the result
if blocked_instances is not None:
print(f"Blocked instances for {instance_to_check}:")
for instance in blocked_instances:
print(f"- {instance}")
else:
print(f"No instance found for {instance_to_check}")
This script first loads the JSON data and parses it into a Python dictionary. Then, it defines a function get_blocked_instances
that takes a domain as input and returns the list of blocked instances for that domain. Finally, it takes the user input for the instance to check and prints the list of blocked instances for that domain.
Citations:
[1] https://stackoverflow.com/questions/14048948/how-to-find-a-particular-json-value-by-key
[2] https://ankushkunwar7777.medium.com/get-data-from-large-nested-json-file-cf1146aa8c9e
[3] https://www.geeksforgeeks.org/read-json-file-using-python/
[4] https://pynative.com/python-check-if-key-exists-in-json-and-iterate-the-json-array/
[5] https://hackersandslackers.com/extract-data-from-complex-json-python/
How to link to a community without redirecting people to other instance? There is a right way to do this but I never remember.
No