How do I completely remove colorama from this?


Milou

I got this code from a friend, but since he's on linux he has colorama in it and it doesn't work for me, it's hard to read and/or copy and paste the results when the color codes are there. What do I need to edit to not include colorama?

#!/usr/bin/python3
import requests
import json
import sys
import struct
import socket
import colorama
from colorama import Fore

indent = "  "


def ip2bin(ip):  # Credit to converter
    binary = bin(struct.unpack('!I', socket.inet_aton(ip))[0])
    return binary


def arg_length():
    return len(sys.argv)


def print_help():
    print("Commands:")
    print("** ipl -i <ip> - Gets information from an IP address")
    print("** ipl -h - Displays this page.")


def lookup(ip):
    print("Looking up IP address \"" + str(ip) + "\"..")

    re = requests.get("https://ipinfo.io/" + str(ip) + "/json")

    j = json.loads(re.content)

    postal = ''
    loc = ''
    hostname = ''

    print("IP Information:")

    for key, value in j.items():
        maininfo = True
        if str(key) == "error":
            print("Error: Invalid IP address")
            exit(0)
        if str(key) != "readme":
            if key == "postal":
                postal = value
                maininfo = False
            if key == "loc":
                loc = value
                maininfo = False
            if key == 'hostname':
                loc = value
                maininfo = False
            if maininfo:
                print(indent + key, "-", Fore.BLUE + value + Fore.WHITE)

    binary = ip2bin(ip).replace('0b', '')

    ipClass = 'Class '

    if binary.startswith("0"):
        ipClass += 'A'

    elif binary.startswith('10'):
        ipClass += 'B'

    elif binary.startswith('110'):
        ipClass += 'C'

    elif binary.startswith('1110'):
        ipClass += 'D'

    elif binary.startswith('1111'):
        ipClass += 'E'

    print("Additional Information:")
    print(indent + "IP Class: " + Fore.BLUE + ipClass + Fore.WHITE)
    print(indent + "Postal Code: " + Fore.BLUE + postal + Fore.WHITE)
    print(indent + "Long/Lat: " + Fore.BLUE + loc + Fore.WHITE)
    if not hostname == '':
        print("Hostname: " + hostname)


if arg_length() == 1 or arg_length() == 2:
    print_help()
if arg_length() == 3:
    if str(sys.argv[1]) == "-i":
        lookup(str(sys.argv[2]))
    else:
        print_help()
peaceful james

Just remove all uses of colorama and Fore like this:

#!/usr/bin/python3
import requests
import json
import sys
import struct
import socket

indent = "  "


def ip2bin(ip):  # Credit to converter
    binary = bin(struct.unpack('!I', socket.inet_aton(ip))[0])
    return binary


def arg_length():
    return len(sys.argv)


def print_help():
    print("Commands:")
    print("** ipl -i <ip> - Gets information from an IP address")
    print("** ipl -h - Displays this page.")


def lookup(ip):
    print("Looking up IP address \"" + str(ip) + "\"..")

    re = requests.get("https://ipinfo.io/" + str(ip) + "/json")

    j = json.loads(re.content)

    postal = ''
    loc = ''
    hostname = ''

    print("IP Information:")

    for key, value in j.items():
        maininfo = True
        if str(key) == "error":
            print("Error: Invalid IP address")
            exit(0)
        if str(key) != "readme":
            if key == "postal":
                postal = value
                maininfo = False
            if key == "loc":
                loc = value
                maininfo = False
            if key == 'hostname':
                loc = value
                maininfo = False
            if maininfo:
                print(indent + key, "-", value)

    binary = ip2bin(ip).replace('0b', '')

    ipClass = 'Class '

    if binary.startswith("0"):
        ipClass += 'A'

    elif binary.startswith('10'):
        ipClass += 'B'

    elif binary.startswith('110'):
        ipClass += 'C'

    elif binary.startswith('1110'):
        ipClass += 'D'

    elif binary.startswith('1111'):
        ipClass += 'E'

    print("Additional Information:")
    print(indent + "IP Class: " + ipClass)
    print(indent + "Postal Code: " + postal)
    print(indent + "Long/Lat: " + loc)
    if not hostname == '':
        print("Hostname: " + hostname)


if arg_length() == 1 or arg_length() == 2:
    print_help()
if arg_length() == 3:
    if str(sys.argv[1]) == "-i":
        lookup(str(sys.argv[2]))
    else:
        print_help()

I think people voted against you because you showed a lack of effort. However, it took me 20 seconds to solve your question, so I don't mind answering.

Better to just use my answer and delete your question.

Related


How do I completely remove the DropBox daemon?

username I installed the DropBox daemon following these instructions : cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf - But now I found out that there is a more appropriate way to install via their official repositories and APT

How do I completely remove my Emacs?

Yang Wenhao I downloaded the Emacs source files and installed using make. After a successful installation of Emacs, I manually deleted the downloaded source files to save disk space. Now I want to remove Emacs and try it sudo apt-get purge emacs. But it says E

How do I completely remove my Emacs?

Yang Wenhao I downloaded the Emacs source files and installed using make. After a successful installation of Emacs, I manually deleted the downloaded source files to save disk space. Now I want to remove Emacs and try it sudo apt-get purge emacs. But it says E

How do I completely remove my Emacs?

Yang Wenhao I downloaded the Emacs source files and installed using make. After a successful installation of Emacs, I manually deleted the downloaded source files to save disk space. Now I want to remove Emacs and try it sudo apt-get purge emacs. But it says E

How do I completely remove the desktop?

БJовић I wanted to switch to Xfce (I have KDE and GNOME installed) and I did: sudo apt-get install xubuntu-desktop sudo apt-get remove kubuntu-desktop sudo apt-get remove ubuntu-desktop sudo apt-get autoremove But to my surprise, I can still choose gnome, kde

How do I completely remove Brave?

I received I installed Brave a while ago, but I didn't like it so I removed it with sudo apt-get remove --purge brave-browser. After a while I had to reinstall it because I needed a Chromium based browser. As soon as I opened it, it asked to redeem my old BAT,

How do I completely remove my Emacs?

Yang Wenhao I downloaded the Emacs source files and installed using make. After a successful installation of Emacs, I manually deleted the downloaded source files to save disk space. Now I want to remove Emacs and try it sudo apt-get purge emacs. But it says E

How do I completely remove the DropBox daemon?

username I installed the DropBox daemon following these instructions : cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf - But now I found out that there is a more appropriate way to install via their official repositories and APT

How do I completely remove my Emacs?

Yang Wenhao I downloaded the Emacs source files and installed using make. After a successful installation of Emacs, I manually deleted the downloaded source files to save disk space. Now I want to remove Emacs and try it sudo apt-get purge emacs. But it says E

How do I completely remove my Emacs?

Yang Wenhao I downloaded the Emacs source files and installed using make. After a successful installation of Emacs, I manually deleted the downloaded source files to save disk space. Now I want to remove Emacs and try it sudo apt-get purge emacs. But it says E

How do I completely remove the desktop?

БJовић I wanted to switch to Xfce (I have KDE and GNOME installed) and I did: sudo apt-get install xubuntu-desktop sudo apt-get remove kubuntu-desktop sudo apt-get remove ubuntu-desktop sudo apt-get autoremove But to my surprise, I can still choose gnome, kde

How do I completely remove Brave?

I received I installed Brave a while ago, but I didn't like it so I removed it with sudo apt-get remove --purge brave-browser. After a while I had to reinstall it because I needed a Chromium based browser. As soon as I opened it, it asked to redeem my old BAT,

How do I completely remove a .deb with the wrong installation?

Simon Whenever I try to use dpkgor apt-get, I get a warning: dpkg: warning: parsing file '/var/lib/dpkg/available' near line 12674 package 'jarnal': error in Version string 'build901': version number does not start with digit Looking at /var/lib/dpkg/availab