this post was submitted on 15 Jun 2023
37 points (97.4% liked)

FREEMEDIAHECKYEAH

53 readers
1 users here now

๐Ÿฟ ๐Ÿ“บ ๐ŸŽต ๐ŸŽฎ ๐Ÿ“— ๐Ÿ“ฑ


๐Ÿดโ€โ˜ ๏ธ Wiki / ๐Ÿ’ฌ Chat


Rules

1. Please be kind and helpful to one another.

2. No racism, sexism, ableism, homophobia, transphobia, spam.

3. Linking to piracy sites is fine, but please keep links directly to pirated content in DMs.

founded 2 years ago
MODERATORS
 

Can we see somewhere what instances block us?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] InternetPirate@lemmy.fmhy.ml -3 points 2 years ago

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/