I have a BATCH file that automatically runs my Birthday Pokemon generator indefinitely. It was working fine until I installed Pyenv to down grade my Python to 3.8.10 temporarily to install a specfic module. After reinstalling all the required modules using PIP, the BATCH file stopped looping.
The BATCH file is below, and under is the initial script.
@echo off
python Pokemon.py
:loop
if %ERRORLEVEL% == 0 (
python Pokemon.py
) else (
echo Exited with code: %ERRORLEVEL%
pause
)
goto loop
Pokemon Generator:
#Imports
import pypokedex
import pypokedex.exceptions
import datetime
import os
import json
import random
#Code
birthDate: str = input("Input your birth date n")
birthMonth: str = input("Input your birth month n")
birthYear: str = input("Input your birth year n")
today: datetime.date = datetime.date.today()
year: int = today.year
asking: bool = True
currentDir = os.path.dirname(__file__)
pokemonJson: str = os.path.join(currentDir, "AmountOfPokemon.json")
with open(pokemonJson, "r") as file:
pokemonData: dict[str, str] = json.load(file)
while asking:
if len(birthMonth) == 0 or len(birthMonth) > 2 or not birthMonth.isdigit():
print("input valid birth date.")
birthDate = input("Input your birth date n")
if len(birthDate) == 0 or len(birthDate) > 2 or not birthDate.isdigit():
print("input valid birth date.")
birthMonth = input("Input your birth month n")
if len(birthYear) != 4 or not birthYear.isdigit():
print("input valid birth date.")
birthYear = input("Input your birth year n")
if birthDate.isdigit() and int(birthDate) > 31:
print("input valid birth date.")
birthDate = input("Input your birth date n")
if birthMonth.isdigit() and int(birthMonth) > 12:
print("input valid birth month.")
birthDate = input("Input your birth month n")
if birthYear.isdigit() and int(birthYear) > year:
print("input valid birth year.")
birthYear = input("Input your birth year n")
if (len(birthMonth) != 0 or len(birthMonth) <= 2 or birthMonth.isdigit()) and (birthDate.isdigit() and int(birthDate) <= 31) and (birthMonth.isdigit() and int(birthMonth) <= 12) and (birthYear.isdigit() and int(birthYear) <= year):
asking = False
pokemonNumber = 0
operation = random.randint(1, 2)
number: int = random.randint(1, 50)
if operation == 1:
pokemonNumber = round( int(birthYear) / (int(birthMonth) + int(birthDate))) + number
elif operation == 2:
pokemonNumber = round( int(birthYear) / (int(birthMonth) + int(birthDate))) - number
def getPokemonNumber() -> tuple[int, str]:
global pokemonNumber
print(pokemonNumber)
if pokemonNumber <= 0 or pokemonNumber > 1025:
pokemonNumber = 0
pokemon = "Missingno"
return pokemonNumber, pokemon
if int(birthMonth) == 7 and int(birthDate) == 1:
pokemonNumber = 399
pokemon = "Bidoof"
return pokemonNumber, pokemon
try:
pokemon: pypokedex.Pokemon | str = pypokedex.get(dex=pokemonNumber)
except pypokedex.exceptions.PyPokedexError:
pokemon = pokemonData[str(pokemonNumber)] #If getting the POkemon fails due to a network error, fall back to using the JSON file.
if isinstance(pokemon, pypokedex.Pokemon):
return pokemon.dex, pokemon.name.capitalize()
else:
return pokemonNumber, pokemon.capitalize()
playersPokemon: str = getPokemonNumber()[1]
pokemonsNumber: int = getPokemonNumber()[0]
print(f"Your Pokémon is #{pokemonsNumber}: {playersPokemon}, based on your birthday.")
I’ve tried adding a pause at the end of the script. However, pause does not work anymore in BATCH files after installing Pyenv.