Пример #1
0
def print_menu(stdscr, selected_row_idx):
    """This prints the main menu on the screen using cureses library
    """
    stdscr.clear()

    curses.init_pair(2, curses.COLOR_CYAN, 0)

    try:
        text = fig('Honey... I don\'t know', font='starwars')
        stdscr.attron(curses.color_pair(2))
        stdscr.addstr(0, 0, text)
        stdscr.attroff(curses.color_pair(2))
    except curses.error:
        pass

    h, w = stdscr.getmaxyx()
    for idx, row in enumerate(menu):
        x = w // 2 - len(row) // 2
        y = h // 2 - len(menu) // 2 + idx
        if idx == selected_row_idx:
            stdscr.attron(curses.color_pair(1))
            stdscr.addstr(y, x, row)
            stdscr.attroff(curses.color_pair(1))
        else:
            stdscr.addstr(y, x, row)
    stdscr.refresh()
Пример #2
0
    def display_fig(self, text: str):
        """Display a large text figure.

        Keyword arguments:
        text -- str

        Using the pyfiglet module, the text string is transformed into a large text figure and is then printed.
        """
        logo = fig(text)
        print(logo)
Пример #3
0
def main():
    """main line function"""
    # dir() will print out all the functions within an object
    # print(dir(termcolor))
    # help(termcolor)

    #text = colored("hello", "red", "on_yellow")
    # print(text)
    f = fig(font="slant")
    ascii_art = f.renderText(text="Right Solutions Group")
    print(ascii_art)
    colored_art = colored(ascii_art, "red", "on_yellow")
    print(colored_art)
Пример #4
0
from requests import get
from pyfiglet import figlet_format as fig
from termcolor import colored as color

header = color(fig("DAD JOKES 2020"), 'yellow')
print(header)

url = 'https://icanhazdadjoke.com/search'

term = input('Let me tell you a joke! Give me topic, please: ')

res = get(url, headers={
    'Accept': 'application/json'
}, params={
    "term": term
}).json()

res_num = res['total_jokes']
results = res['results']
desired_num_jokes = 0
displayed_jokes = 0
result_num = 0
if res_num == 0:
    print(
        f'Sorry, I have no jokes about {term}. Please, try a different topic.')
elif res_num == 1:
    print(f'I have one joke about {term}. Here it is:')
    print(results[0]['joke'])
else:
    desired_num_jokes = input(
        f'I have {res_num} jokes about {term}.\nHow many do you want? MAX=20 ')
Пример #5
0
from pyfiglet import figlet_format as fig
from termcolor import colored
import requests
from random import choice

title = fig("Dad Joke 3000")
title = colored(title, color="magenta")
print(title)
topic = input("Let me tell you a joke! Give me a topic: ")
url = "https://icanhazdadjoke.com/search"
res = requests.get(url,
                   headers={
                       "Accept": "application/json"
                   },
                   params={
                       "term": topic
                   }).json()

num_jokes = res["total_jokes"]
results = res["results"]

if num_jokes > 1:
    print(f"I found {num_jokes} about {topic}. Here is one: ")
    print(choice(results)['joke'])
elif num_jokes == 1:
    print(f"There is one joke about {topic}")
    print(results[0]['joke'])
else:
    print(f"Sorry, couldn't find the joke with your term: {topic}")
Пример #6
0
from pyfiglet import figlet_format as fig
from termcolor import colored
from colorama import init

# use colorama to make colours work on windows
init()

valid_colors = ("red", "green", "yellow", "blue", "magenta", "cyan", "white")

msg = input("What would you like to say? ")
print("\nred, green, yellow, blue, magenta, cyan, white")
color = input("What colour? ")

if color not in valid_colors:
    color = "magenta"

ascii_msg = fig(msg)
colored_ascii = colored(ascii_msg, color)

print(colored_ascii)
Пример #7
0
# dad joke 9001
from pyfiglet import figlet_format as fig
from termcolor import colored
from colorama import init
import requests
from random import choice

# use colorama to make colours work on windows
init()

intro = "Dad Joke 9001"
intro_color = "cyan"
intro_final = colored(fig(intro), intro_color)

print(intro_final)

topic = input("Have I got a joke for you!\nGimme a topic, any topic: ")
url = "https://icanhazdadjoke.com/search"
response = requests.get(url,
                        headers={
                            "Accept": "application/json"
                        },
                        params={
                            "term": topic
                        }).json()

total = response["total_jokes"]
results = response["results"]

if total == 0:
    print(f"Sorry, there are {total} jokes about {topic}.")
Пример #8
0
def print_history(stdscr):
    """Prints the history part of the menu, creating three lists for each type of history data we are saving
    """
    stdscr.clear()
    try:
        user_list, order_list, history_list = history.get_full_info()
    except ValueError:
        user_list, order_list, history_list = [['Number of orders by user'],
                                               ['Orders by food category'],
                                               ['History of all the orders']]

    curses.init_pair(2, curses.COLOR_CYAN, 0)
    curses.init_pair(3, curses.COLOR_CYAN, 0)
    try:
        text = fig('Honey... I don\'t know', font='starwars')
        stdscr.attron(curses.color_pair(2))
        stdscr.addstr(0, 0, text)
        stdscr.attroff(curses.color_pair(2))
    except curses.error:
        pass
    h, w = stdscr.getmaxyx()

    # Printing the Number of orders by User
    for idx, item in enumerate(user_list):
        x = 5
        y = (h // 4) * 2 + 3 + idx
        if idx == 0:
            try:
                stdscr.attron(curses.color_pair(3))
                stdscr.addstr(y, x, item)
                stdscr.attroff(curses.color_pair(3))
            except curses.error:
                pass
        elif idx % 2 == 0:
            try:
                stdscr.addstr(y, x, item, curses.A_DIM)
            except curses.error:
                pass
        else:
            try:
                stdscr.addstr(y, x, item)
            except curses.error:
                pass

    # Printing Orders by food category
    for idx, item in enumerate(order_list):
        x = (w // 5) * 2
        y = h // 3 + idx
        if idx == 0:
            stdscr.attron(curses.color_pair(3))
            stdscr.addstr(y, x, item)
            stdscr.attroff(curses.color_pair(3))
        elif idx % 2 == 0:
            try:
                stdscr.addstr(y, x, item, curses.A_DIM)
            except curses.error:
                pass
        else:
            try:
                stdscr.addstr(y, x, item)
            except curses.error:
                pass

    # History of all the orders
    for idx, item in enumerate(history_list):
        x = (w // 5) * 3 + 10
        y = h // 3 + idx
        if idx == 0:
            stdscr.attron(curses.color_pair(3))
            stdscr.addstr(y, x, item)
            stdscr.attroff(curses.color_pair(3))
        elif idx % 2 == 0:
            try:
                stdscr.addstr(y, x, item, curses.A_DIM)
            except curses.error:
                pass
        else:
            try:
                stdscr.addstr(y, x, item)
            except curses.error:
                pass
    stdscr.refresh()
Пример #9
0
from pyfiglet import figlet_format as fig
import requests
from random import randrange as rand

msg = "Dad Joke 3000"
title = fig(msg)
print(title)
print()

response = input("Let me tell you a joke! Give me a topic: ")
url = "https://icanhazdadjoke.com/search"

if response == "":
    print("Here's a random joke:")
    res = requests.get(url, headers={"Accept": "application/json"})
else:
    res = requests.get(url,
                       headers={"Accept": "application/json"},
                       params={'term': response})

data = res.json()
jokes = data['results']

if len(jokes) > 1:
    if response != "":
        print(f"I've got {len(jokes)} about {response}. Here's one:")
    print(jokes[rand(1, len(jokes))]['joke'])
elif len(jokes) == 1:
    print(f"I've got a joke about {response}. Here it is:")
    print(jokes[0]['joke'])
else:
Пример #10
0
from pyfiglet import figlet_format as fig
from termcolor import colored

valid_colors = ('red', 'green', 'yellow', 'blue', 'magenta', 'cyan')

msg = input("Enter text to print: ")
color = input("Color: ")

if color not in valid_colors: color = 'magenta'

ascii_art = fig(msg)
colored_ascii = colored(ascii_art, color=color)

print(ascii_art)
Пример #11
0
from pyfiglet import figlet_format as fig
from termcolor import colored

message = input("What message do you want to print? ")
color = input("What color? ")

result = fig(message)
if color in ("red", "green", "yellow", "blue", "magenta", "cyan", "white"):
    result = colored(result, color)
    print(result)
else:
    result = colored(result, "red")
    print(result)