WYGIWYG

  • 0 Posts
  • 6 Comments
Joined 5 months ago
cake
Cake day: September 24th, 2024

help-circle
  • He couldn’t even shut down USA aid. All he needed to do was have a semi-intelligent person walk into there and see what the consequences would be for shutting it down. He’s consistently just playing checkers on a chess board and having to roll every move back.

    He’s going to piss a lot more people off and make a lot more problems but he does not have the competency in himself or his team to pull off an operation like that against an actual trained country.

    Don’t get me wrong, he will eventually shut a bunch of very important shit down probably inadvertently.

    Maybe we’ll lose a third of the population to an illness or something on his watch.

    I’m a bit more worried overall that he’s now going to permanently be in power than anything. I don’t think the US has it in them too kick him to the curb, and I’m definitely not going to count on the military backing us in a coup.






  • So, you don’t know Python at all AND you don’t know Bash, but you feel compelled to talk about how one is so much better than the other?

    1. Python has a lot of compatibility problems, you have to roll the env system and do requirements, and if your distro doesn’t have those packages available, you can’t run the script. Then you can’t always run python 2 code in python 3.

    2. Bash has error handling and try/catch.

    3. Cross platfoming a shell script to run in ba, bash in linux, wsl and mac is fairly straight forward. Worst case, if you don’t have a specific flavor of bash installed, you can always install it. You rely on the posix compliance of the OS binaries to get the job done.

    -------Bash------
    
    #!/usr/bin/env bash
    
    API_URL="https://api.example.com/data"
    
    CONNECT_TIMEOUT=5   
    MAX_TIME=10         
    
    response=$(
      curl \
        --silent \
        --write-out "\n%{http_code}" \
        --connect-timeout "$CONNECT_TIMEOUT" \
        --max-time "$MAX_TIME" \
        "$API_URL"
    )
    
    http_body=$(echo "$response" | sed '$d')        
    http_code=$(echo "$response" | tail -n1)
    
    curl_exit_code=$?
    
    if [ $curl_exit_code -ne 0 ]; then
      echo "Error: Failed to connect or timed out (curl exit code $curl_exit_code)."
      exit 1
    fi
    
    if [ -z "$http_code" ]; then
      echo "Error: No HTTP status code received. The request may have timed out or failed."
      exit 1
    fi
    
    echo "HTTP status code: $http_code"
    
    if [ "$http_code" -eq 200 ]; then
      echo "Request successful! Parsing JSON response..."
      echo "$http_body" | jq
    else
      echo "Request failed with status code $http_code. Response body:"
      echo "$http_body"
      exit 1
    fi
    
    exit 0
    
    
    -------------Python-------------
    #!/usr/bin/env python3
    
    import requests
    import sys
    
    def main():
        # API endpoint
        API_URL = "https://api.example.com/data"
    
        # Timeout (in seconds)
        TIMEOUT = 5
    
        try:
            # Make a GET request with a timeout
            response = requests.get(API_URL, timeout=TIMEOUT)
    
            # Check the HTTP status code
            if response.status_code == 200:
                # Parse the JSON response
                try:
                    data = response.json()
                    print("Request successful. Here is the parsed JSON data:")
                    print(data)
                except ValueError as e:
                    print("Error: Could not parse JSON response.", e)
                    sys.exit(1)
            else:
                # Handle non-200 status codes
                print(f"Request failed with status code {response.status_code}.")
                print("Response body:", response.text)
                sys.exit(1)
    
        except requests.exceptions.Timeout:
            print(f"Error: The request timed out after {TIMEOUT} seconds.")
            sys.exit(1)
        except requests.exceptions.RequestException as e:
            # Catch all other requests-related errors (e.g., connection error)
            print(f"Error: An error occurred while making the request: {e}")
            sys.exit(1)
    
    if __name__ == "__main__":
        main()