-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
114 lines (88 loc) · 2.85 KB
/
main.py
File metadata and controls
114 lines (88 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import random
import requests
import secrets
base_url = "https://pokeapi.co/api/v2/"
class Pokemon:
def __init__(self, name, pid, ability):
self.name = name
self.pid = pid
self.ability = ability
# def __str__(self):
# return f"{self.name}({self.pid})"
def get_pokemon_info(name):
url = f"{base_url}/pokemon/{name}"
response = requests.get(url)
if response.status_code == 200:
pokemon_data = response.json()
return pokemon_data
else:
print(f"Failed to retrieve data {response.status_code}")
def generate_password(roster):
random.shuffle(roster)
count = 0
password = ""
for x in roster:
password += str(x.pid)
if count != 3:
password += ":"
if count == 3:
finishingTouch = "@" + secrets.choice(roster).ability.capitalize()
password += finishingTouch
count += 1
print(password)
return password
def prompt():
roster = []
print("To create a password, enter 4 Pokemon")
i = 0
while i < 4:
pokemon_name = input()
pokemon_info = get_pokemon_info(pokemon_name)
if pokemon_info:
i += 1
name = pokemon_info['name'].capitalize()
pokeID = pokemon_info['id']
ability = secrets.choice(pokemon_info['abilities']).get('ability')['name']
sprite = pokemon_info['sprites']['front_default']
roster.append(Pokemon(name, pokeID, ability))
else:
print("Please enter a valid pokemon")
generate_password(roster)
# prompt()
def random_generate():
roster = []
print("Generate a password using 4 Pokemon...")
i = 0
while i < 4:
pokemon_name = random.randrange(1, 1026)
pokemon_info = get_pokemon_info(pokemon_name)
if pokemon_info:
i += 1
# print(f"Name: {pokemon_info['name'].capitalize()}")
# print(f"Id: {pokemon_info['id']}")
# print(f"Ability: {pokemon_info['abilities'][0].get('ability')['name']}")
name = pokemon_info['name'].capitalize()
pokeID = pokemon_info['id']
ability = secrets.choice(pokemon_info['abilities']).get('ability')['name']
roster.append(Pokemon(name, pokeID, ability))
else:
print("Please enter a valid pokemon")
newpass = generate_password(roster)
return newpass
# random_generate()
def main():
print("Welcome to Poke Password, to start enter 1 to randomly generate password or 2 to enter pokemon one by one")
userinput = input()
if userinput == '1':
random_generate()
elif userinput == '2':
prompt()
else:
main()
print("Run Again? 1 for Yes, 2 for No")
secondinput = input()
if secondinput == '1':
main()
elif secondinput =='2':
print("Bye Bye")
main()