示例#1
0
def _get_(url):
    log = config_logger()
    log.debug(f"GET:\t{url}")
    response = requests.request("GET", url)
    log.debug(f"Status: {response.status_code}")
    if not response.status_code == 200:
        return None
    return response.json()
示例#2
0
def main():
    load_dotenv()
    log = logging.config_logger()
    arguments = args.get_args()

    log.info(f"Session start at: {dt.now()}")

    print_header()

    pokemon = arguments.pokemon
    another = True

    while another:
        if pokemon is None:
            pokemon = input("Enter pokemon name or number: ")

        log.info(f"Searching for pokemon: {pokemon}...")
        pokemon_info = api.get_pokemon_info(pokemon.lower())

        if pokemon_info is None:
            print(f"The requested pokemon [{pokemon}] doesn't exists!")
        else:
            log.info(f"Pokemon found! Searching for pokemon species for id: {pokemon_info['id']}...")
            species = api.get_species(pokemon_info['id'])
            print_pokemon_name(pokemon_info['name'])
            print_pokemon_info(pokemon_info)
            print_pokemon_species(species)
            print("*" * 64)
            print("Please close the window before continue...")
            image.show_window(pokemon_info)

        search_again = input("Search another pokemon? (y/n)")

        if search_again == "y" or search_again == "Y":
            another = True
            pokemon = None
        else:
            another = False

    log.info(f"Session end at: {dt.now()}")
示例#3
0
def show_window(pokemon_info: dict):
    log = config_logger()

    main_window = tk.Tk()

    image_url = pokemon_info["sprites"]["other"]["official-artwork"]["front_default"]
    log.debug(f"image_url: {image_url}")
    img_data = get_pokemon_img_data(image_url)
    img = ImageTk.PhotoImage(Image.open(BytesIO(img_data)))

    sprite_url = pokemon_info["sprites"]["front_default"]
    log.debug(f"sprite_url: {sprite_url}")
    sprite_data = get_pokemon_img_data(sprite_url)
    sprite = ImageTk.PhotoImage(Image.open(BytesIO(sprite_data)))

    main_window.iconphoto(False, sprite)
    main_window.title(pokemon_info["name"].upper())
    b_image = tk.Button(main_window, image=img, command=main_window.destroy)
    b_image.pack(side="bottom", fill="both", expand="yes")

    log.info("Opening image-window...")
    main_window.mainloop()
示例#4
0
from logging import INFO

from config.logging import config_logger

config_logger(
    logger_name=__name__,
    log_level=INFO,
    message_sublevel=True,
)
示例#5
0
from logging import INFO

from config.logging import config_logger

config_logger(
    logger_name=__name__,
    log_level=INFO,
)