def edit(): print(termcolor2.colored("Product_Id Or Product_Name", color="blue")) user_edit = input("Enter Choice: ") for product in product_list: if product["id"] == user_edit or product["name"] == user_edit: print(termcolor2.colored(f"Product: {product}", color="green")) user_product = input("Which Part To Edit? ") if user_product == "id": id = int(input("Enter New Id: ")) product["id"] = id break elif user_product == "name": name = input("Enter New Name: ") product["name"] = name break elif user_product == "price": price = input("Enter New Price: ") product["price"] = price break elif user_product == "count": count = input("Enter New Count: ") product["count"] = count break else: print(termcolor2.colored("No Product", color="red"))
def sum(): h1 = int(input("Enter Hour1: ")) m1 = int(input("Enter Minutes1: ")) if 0 > m1 or m1 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() s1 = int(input("Enter Seconds1: ")) if 0 > s1 or s1 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() h2 = int(input("Enter Hour2: ")) m2 = int(input("Enter Minutes2: ")) if 0 > m2 or m2 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() s2 = int(input("Enter Seconds2: ")) if 0 > s2 or s2 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() result1 = {"h": h1, "m": m1, "s": s1} print(result1["h"], ":", result1["m"], ":", result1["s"], end="\t") result2 = {"h": h2, "m": m2, "s": s2} print(result2["h"], ":", result2["m"], ":", result2["s"]) result3 = {"h": h1 + h2, "m": m1 + m2, "s": s1 + s2} return result3
def remove(): print(termcolor2.colored("Product_Id Or Product_Name", color="blue")) user_remove = input("Enter Choice: ") for product in product_list: if product["id"] == user_remove or product["name"] == user_remove: print(termcolor2.colored(f"Product: {product}", color="green")) product_list.remove(product) print(termcolor2.colored("Was Deleted", color="red")) break else: print(termcolor2.colored("No Product", color="red"))
def installSshpass(file): print colored('In order to install sshpass your laptop user password is required, please enter it now', 'yellow') passwd = getpass.getpass() with tarfile.open(file, "r:gz") as tar: tar.extractall() print colored('Now installing sshpass!', 'yellow') os.system(''' cd sshpass-{} ./configure make echo {} | sudo -S make install '''.format(sshpass_version, passwd))
def search(): print(termcolor2.colored("*Id* Or *Name*", color="blue")) user_search = input("Enter Choice: ") for product in product_list: if product["id"] == user_search or product["name"] == user_search: print( termcolor2.colored(f"Desired Product: {product}", color="green")) break else: print(termcolor2.colored("No Product", color="red"))
def processSniffedPacket(packet): if packet.haslayer(http.HTTPRequest): url = packet[http.HTTPRequest].Host + packet[http.HTTPRequest].path print(termcolor2.colored(url, 'blue')) if packet.haslayer(scapy.raw): load = packet[scapy.raw].load keywords = [ "username", "user", "login", "pass", "password", "email", "mail" ] for keyword in keywords: if keyword in load: print(termcolor2.colored(load, 'red')) break
def main(): cmd = 'which sshpass > /dev/null 2>&1' try: subprocess.check_call(cmd, shell=True) print colored('sshpass is installed!', 'green') except subprocess.CalledProcessError as e: print colored('sshpass not installed! installing...', 'red') downloadSshpass(url) installSshpass(home+'/'+sshpass_filename) backupSshConfig() sshConfig(ip_list) sshCopyId(ip_list, password) cleanGarbage()
def pretty_print_str(data, args_pretty={}): args_pretty.setdefault('color', 'green') args_pretty.setdefault('on_color', None) args_pretty.setdefault('attrs', []) data = [el.ljust(LEN_STR_PRINT) for el in data.split('\n')] data = '\n'.join(data) print(colored(data, *args_pretty.values()))
def pretty_print_table(data, args_pretty={}, n=10): args_pretty.setdefault('color', 'yellow') args_pretty.setdefault('on_color', None) args_pretty.setdefault('attrs', ['bold']) #pretty_print_str(f'всего к выводу {len(data)} записей: ', args_pretty) print(colored(data, *args_pretty.values()))
def buy(): print(termcolor2.colored("Product_Id Or Product_Name", color="blue")) user_remove = input("Enter Choice: ") for product in product_list: if product["id"] == user_remove or product["name"] == user_remove: print(termcolor2.colored(f"Product: {product}", color="green")) user_count = input("Enter Number: ") if product["count"] > user_count: result = int(product["count"]) - int(user_count) print( termcolor2.colored(f"Your Cart:Count {result}", color="green")) break else: print(termcolor2.colored("Count Not Enough", color="red")) break else: print(termcolor2.colored("No Product", color="red"))
def server_info(): print(termcolor2.colored(""" ####################################################################################### ## ## ## #### ## ## ###### ######## ### ## ## ### ## ## ######## ## ## ## ### ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## #### ## ## ## ## ## #### ## ## ## ## ## ## ## ## ## ## ## ## ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #### ## ## ######### ## #### ######### ## ## ## ## ## ## ## ### ## ## ## ## ## ## ### ## ## ## ## ## ## ## #### ## ## ###### ## ## ## ## ## ## ## ####### ## ## ## ## ####################################################################################### """, "yellow")) print(termcolor2.colored(""" ################################################################################ ## ## ## + DEV CONTACTS IF HELP NEEDED ## ## - INSTAGRAM => https://www.instagram.com/_avi.exe/ ## ## - GITHUB => https://github.com/git-avinash ## ## ## ## + CONTRIBUTE TO INSTANAUT ## ## - SERVER *PYTHON* => https://github.com/git-avinash/Instanaut-Server- ## ## - GUI *DART* => https://github.com/git-avinash/Instanaut-GUI- ## ## ## ## + OPENSOURCE LICENCE ## ## Copyright 2020 Avinash S Sah ## ## SPDX-License-Identifier: Apache-2.0 ## ## ## ################################################################################ """, "blue")) print(termcolor2.colored(f""" - [SERVER VERSION] 1.0.0+2 - [RECOMMENDED APP VERSION] 1.0.0+1 ANDROID & WINDOWS - [IP] {socket.gethostbyname(socket.gethostname())} - [PORT] 5050 """, "green")) print(termcolor2.colored(""" SERVER LOGS BELOW ***************** """, "red"))
def __init__(self): self.hour1 = int(input("Enter Hour1: ")) self.minutes1 = int(input("Enter Minutes1: ")) if 0 > self.minutes1 or self.minutes1 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() self.seconds1 = int(input("Enter Seconds1: ")) if 0 > self.seconds1 or self.seconds1 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() self.hour2 = int(input("Enter Hour2: ")) self.minutes2 = int(input("Enter Minutes2: ")) if 0 > self.minutes2 or self.minutes2 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() self.seconds2 = int(input("Enter Seconds2: ")) if 0 > self.seconds2 or self.seconds2 > 60: print(termcolor2.colored("TryAgain", color="red")) exit()
def all_exit(): user_exit = input( termcolor2.colored("Do You Want The Information To Be Saved: ", color="blue")) if user_exit == "yes": file = open("database.csv", "a") for product in product_list: file.write(str(f"\n{product}")) exit() else: exit()
def print_log_error(log, summary): colorama.init() print(termcolor2.colored(f"[{summary}] {log}", "red"))
res = Fraction() res.sum() res.show_sum() res.multi() res.show_multi() res.minus() res.show_minus() res.divide() res.show_divide() print(termcolor2.colored("--------------------------------------------", color="red")) print(termcolor2.colored("--------------------------------------------", color="blue")) class Time: def __init__(self): self.hour1 = int(input("Enter Hour1: ")) self.minutes1 = int(input("Enter Minutes1: ")) if 0 > self.minutes1 or self.minutes1 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() self.seconds1 = int(input("Enter Seconds1: ")) if 0 > self.seconds1 or self.seconds1 > 60: print(termcolor2.colored("TryAgain", color="red")) exit() self.hour2 = int(input("Enter Hour2: "))
import termcolor2 print(termcolor2.colored("Fraction Sum: ", color="green")) def total(): s1 = int(input("Enter S1: ")) m1 = int(input("Enter m1: ")) s2 = int(input("Enter S2: ")) m2 = int(input("Enter m2: ")) result = {"s": ((s1 * m2) + (s2 * m1)), "m": m1 * m2} return result res = total() print(res["s"], "/", res["m"]) print(termcolor2.colored("Fraction Multiplication: ", color="green")) def multi(): s1 = int(input("Enter S1: ")) m1 = int(input("Enter m1: ")) s2 = int(input("Enter S2: ")) m2 = int(input("Enter m2: ")) result = {"s": s1 * s2, "m": m1 * m2} return result res = multi() print(res["s"], "/", res["m"])
def sshCopyId(ip_list, password): for ip in ip_list: print colored('#######################################################', 'yellow') print colored('Copying your personal key to ip: {}'.format(ip), 'green') os.system('sshpass -p {} ssh-copy-id -f {}'.format(password, ip))
import termcolor2 import pyfiglet while True: try: fishWeight = int(input(termcolor2.colored("Hi, how much fish did you catch?: ", color = "green"))) except: print("That is not a number") else: break total_price = 0 print("------------------------------------") if fishWeight < 40: total_price += fishWeight print("we pay you:") print(pyfiglet.figlet_format(str(total_price) + ' $')) elif fishWeight >= 40 and fishWeight < 80: total_price += fishWeight * 2 print("we pay you:") print(pyfiglet.figlet_format(str(total_price) + ' $')) elif fishWeight >= 80 and fishWeight < 120: total_price += fishWeight * 3 print("we pay you:") print(pyfiglet.figlet_format(str(total_price) + ' $')) elif fishWeight >= 120 and fishWeight < 500: total_price += fishWeight * 4
import termcolor2 weight = float(input("Enter Weight: ")) height = float(input("Enter Height: ")) bmi = weight / (height * height) if bmi < 18.5: print(termcolor2.colored(f"Condition: {bmi} Underweight", color="blue")) elif 18.5 <= bmi <= 24.9: print(termcolor2.colored(f"Condition: {bmi} Normal", color="green")) elif 25 <= bmi <= 29.9: print(termcolor2.colored(f"Condition: {bmi} Overweight", color="yellow")) elif 30 <= bmi <= 34.9: print(termcolor2.colored(f"Condition: {bmi} Obese", color="orange")) elif 35 >= bmi: print(termcolor2.colored(f"Condition: {bmi} Extremely Obese", color="red"))
import credentials colorama.init() keys = [] try: con = mysql.connector.connect( user=credentials.user, password=credentials.password, host=credentials.host, database=credentials.database ) cursor = con.cursor() except Exception as e: print(termcolor2.colored(("Unable to connect to the database!! Check your internet connection & try again!"),'red')) exit(0) while True: try: word = input("Enter a word: ") query = cursor.execute( "SELECT * FROM Dictionary WHERE Expression ='%s' " % word) results = cursor.fetchall() if results: for result in results: print(termcolor2.colored((result[1]), 'green')) else:
import math import termcolor2 print(termcolor2.colored("---------------------------", color="red")) print("Menu: ") menu = { "Action: +", "Action: -", "Action: *", "Action: /", "Action: **", "Action: log", "Action: sqrt", "Action: sin", "Action: cos", "Action: factorial", "Action: tan" } for men in menu: print(men) print(termcolor2.colored("---------------------------", color="blue")) operator = input("Enter Operator: ") if operator == "sin" or operator == "sqrt" or operator == "cos" or operator == "factorial" or operator == "tan": a = float(input("Enter First Number: ")) else: a = float(input("Enter First Number: ")) b = float(input("Enter Second Number: ")) if operator == "+": print(f"Total: {a + b}") elif operator == "-": print(f"Subtraction: {a - b}") elif operator == "*": print(f"Multiplication: {a * b}") elif operator == "/": if b == 0: print(termcolor2.colored("Cannot Divide By Zero", color="red"))
def print_log(log, summary): colorama.init() print(termcolor2.colored(f"[{summary}] {log}", "green"))
def backupSshConfig(): if isfile('{}/.ssh/config'.format(home)): print colored('Backing up your ssh config file', 'green') os.system('cp {}/.ssh/config {}/.ssh/config.bak_{}'.format(home, home, dt_string)) else: print colored('No configuration file found, not performing backup', 'yellow')
elif len(get_close_matches(w, data.keys())) > 0: matches = "Did you mean %s instead? Enter Y if yes, or N if no: " % get_close_matches( w, data.keys())[0] yn = input(matches) if yn == "Y": return data[get_close_matches(w, data.keys())[0]] elif yn == "N": return "The word doesn't exist. Please double check it." else: return "We didn't understand your entry." else: return "The word doesn't exist. Please double check it." while True: try: word = input("Enter word: ") output = findInDictionary(word) if type(output) == list: for item in output: print(termcolor2.colored((item), 'green')) else: print(termcolor2.colored((output), 'green')) except KeyboardInterrupt as e: print(termcolor2.colored(("Are you really want to quit?y/n :"), 'red')) c = input() if(c.lower() == 'n'): continue else: exit(0)
def sshConfig(ip_list): print colored('Now configuring your {}/.ssh/config file'.format(home), 'green') with open(home+'/.ssh/config', 'a+') as file: for ip in ip_list: file.write("Host {}\nUser {}\nHostName {}\nStrictHostKeyChecking=no\nConnectTimeout=1\n".format(ip, user, ip)) file.write('\n')
class Blocks(Enum): GRASS = colored('x', 'green', 'on_green') BULLET = colored('o', 'red', 'on_green')
def prime_number(): number = int(input("Enter Number: ")) if number % 2 == 1: return termcolor2.colored("True", color="green") else: return termcolor2.colored("False", color="red")
random_index = random.randint(0, 2) cpu_choice = moves[random_index] user_choice = input("Rock, Paper, or Scissors? ").lower() while user_choice not in moves: user_choice = input( "That is not a valid choice. Please try again: ").lower() print("--------------------") print("Your choice:", user_choice) print("Computer's choice:", cpu_choice) if user_choice == 'rock': if cpu_choice == 'rock': print(termcolor2.colored("It's a tie!", color=tieColor)) elif cpu_choice == 'scissors': print(termcolor2.colored("You win!", color=yourColor)) user_wins += 1 elif cpu_choice == 'paper': print(termcolor2.colored("You lose!", color=enemyColor)) computer_wins += 1 elif user_choice == 'paper': if cpu_choice == 'paper': print(termcolor2.colored("It's a tie!", color=tieColor)) elif cpu_choice == 'rock': print(termcolor2.colored("You win!", color=yourColor)) user_wins += 1 elif cpu_choice == 'scissors': print(termcolor2.colored("You lose!", color=enemyColor)) computer_wins += 1
import termcolor2 a = float(input("Enter First Number: ")) b = float(input("Enter Second Number: ")) c = float(input("Enter Third Number: ")) if a + b > c and a + c > b and b + c > a: print(termcolor2.colored("You Can Draw A Triangle ", color="green")) else: print(termcolor2.colored("You Can Not Draw a Triangle", color="red"))
import termcolor2 print(termcolor2.colored('some text', 'blue', "on_white", ["underline"]))